General code explained

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Euphoric Beaver

impeccably groomed
Apr 19, 2001
3,158
0
0
Great Britain
www.euphoric-beaver.me.uk
I've decided to try and make a gun that fires projectiles that when it hits a pawn, they increase slightly in fatness.
Then at a certain point they explode. :D

Code:
auto state Flying
{
	function ProcessTouch (Actor Other, vector HitLocation)
	{
		If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) )
			Explode(HitLocation,Normal(HitLocation-Other.Location));
	}

	function BeginState()
	{
		Velocity = vector(Rotation) * speed;	
	}
}

Now the above code is from ShockProj, which is the altfire of the Shock Rifle.
Now the questions. :D

1) What's that auto doing infront of the state?

2) What's the differance between a processtouch and a touch?

3) What exactly is going on here? This is what I thought.

If the actor hit is not the firer and the actor is a projectile or the actor has a collision radius of none then Explode.

Is this correct?

4) If the above is correct then how does it tell if it's hit any walls or other players?

5)When does the function BeginState get called?
 

EasyRaider

Crazy coder
Sep 21, 2001
74
0
0
43
Norway
1) Objects will begin in this state if InitialState is not set.

2) ProcessTouch() is called from Touch() (defined in Projectile).

3) If actor hit is not the firer and is NOT a projectile or has a collision radius GREATER THAN zero, then explode.

4) When it hits a wall, HitWall() is called, which then calls Explode(). ShockProjs don't need to know if it hits a player.

5) I believe it's called as it enters the state. So if you call someObject.GotoState('Flying'), BeginState() for that state is immediately called.
 

Euphoric Beaver

impeccably groomed
Apr 19, 2001
3,158
0
0
Great Britain
www.euphoric-beaver.me.uk
Thanks. :D

1) How would you set the intial state otherwise?

2) I think I see. So processtouch is just the projectile version of touch?

3) Gotha. I was confused by the ! infront of the Other. :rolleyes:

4) Doesn't need to know because the processtouch sorts everything out.

5) Instead of putting the beginstate(), couldn't they just put the code at the top?

Extra question. :D

6) I think I remember seeing that case doesn't matter. But I notice that everyone is writing like, ProcessTouch.
Would Uscript see these two functions as the same?
ProcessTouch
processtouch
 

Magus

New Member
Oct 7, 2001
69
0
0
Visit site
1. GotoState('NameOfState'); //remember the single quotes around stateName

2,4) Well I will go into a little more detail on Touch for projectiles. Touch is written in the projectile class, and is inherited by all the children of Projectile. All projectiles use the same touch, and there is no need to override it.
When a projectile touches something it does basically two things, determine if it hits a Wall (part of the map), or something else like a player, another projectile, or whatever. When the projectile hits a Wall HitWall(...) is called by Touch, and you put whatever you want to happen to the projectile when it hits a wall in this function in your class. You can do many things in hitwall such as make it explode, bounce off, or what not.
If it hits something that is not a wall ProcessTouch(...) is called by Touch, so when you write ProcessTouch(...) in your class you do whatever you need to do to the object that it hit. So if it hit a pawn, it deals damge, whatever.

5. No you can't put it at the top since, ProcessTouch is not called till it hits an object. BeginState() called when the projectile starts to fly there the air. This sets the velocity of the projectile so that the projectile basicly goes the right way, and at the right angle. Its no good to have a missile flying sideways there the air.

6. It does not really matter how you type the function or variable names in UnrealScript since it is not Case Sensitive like some other languages. In unrealscript Function, function, and FuNcTiOn are the same thing. It all a matter of how easy you want to be able to read it. Captializing the first letter in each work helps, so you dont have to search for the beginning of the next word.
 

EasyRaider

Crazy coder
Sep 21, 2001
74
0
0
43
Norway
Yes, but you should check out these things yourself. Export the scripts from UnrealEd, open them in your favorite text editor, and search for the functions you are interested in. If a function is not defined in a class, it uses the version inherited from its superclass (parent class).
 

Smoke39

whatever
Jun 2, 2001
1,793
0
0
Yes it is. The best thing you can learn is to find code in all the stuff of UT. Well, it's good at least.
 

2COOL4-U

New Member
Mar 17, 2001
505
0
0
37
dot NL
2cool.free.fr
I once started as a complete n00b in UnrealScript(I didn't have any experience with UnrealScript's syntax, only Pascal and Delphi's syntax) but because I looked trough all the code searching for explinations I learned the hierachy of UnrealScript''s objects and learned a lot about having a nice style of writing your code. I really would recommend you looking trough code first and then asking instead of asking if someone knows it first.
 

Euphoric Beaver

impeccably groomed
Apr 19, 2001
3,158
0
0
Great Britain
www.euphoric-beaver.me.uk
I wasn't debating that it's not a good thing to study Epic's code but I thought I asked a pretty simple question that could of been easily answered.

I've learnt alot over the passing days, more then I ever could of learnt staring confuzzled at Epics code but I certainly did not expect an ear bashing for asking questions.

I thought the forum was for asking questions and if somebody happened to knew the question off the top of there head they would answer. :(
 

2COOL4-U

New Member
Mar 17, 2001
505
0
0
37
dot NL
2cool.free.fr
hohoho I don't have a single problem with you asking questions :) it was just a suggestion on how I learned how to code. I saw you posting a lot on this forum and that's good too becuase you are quickly learning things by asking them in the forums instead of figuring it out yourself. I really did not mean to hurt you :)
 

EasyRaider

Crazy coder
Sep 21, 2001
74
0
0
43
Norway
Bots use Bump(). Not sure about the difference between this and Touch(). I wouldn't worry too much about it, unless you need to write new bot AI or something.