Page 1 of 1

Help with script

PostPosted: Mon Oct 26, 2009 2:08 pm
by Zehper48
Hey Everybody,
I'm making a Halo style game, but my question is,
How can I make a variable change its value when the xvelocity of an actor changes its value?
Tell me if I don't make sence =p
Thanks

Re: Help with script

PostPosted: Mon Oct 26, 2009 2:27 pm
by Bee-Ant
Tell me how's the pattern changing?
If the pattern is something like this :
xvelocity : 0 - 1 - 2 - 3 - 4 - 5
variable : 0 - 2 - 4 - 6 - 8 - 10
Then, to change the variable value : actor->DrawActor->
Code: Select all
variable=xvelocity*2;

Re: Help with script

PostPosted: Mon Oct 26, 2009 9:44 pm
by Zehper48
ok, i have a variable, and i need that variable to =1 evertime the xvelocity changes, is that possible?



*edit
there isnt really a pattern



offtopic edit*
does anybody know anything about GE Working with macs?

Re: Help with script

PostPosted: Tue Oct 27, 2009 12:28 am
by Bee-Ant
Do you mean the variable will be 1 if the player move in xvelocity, and the variable will be 0 if the player stopped?
Code: Select all
variable=(abs(xvelocity)>0);

This act :
if xvelocity > 1 or xvelocity < -1 then variable = 1
if xvelocity = 0 then variable = 0

Re: Help with script

PostPosted: Tue Oct 27, 2009 12:44 am
by jimmynewguy
well if i get what your saying then yes. This is really a basic example, but you can figure it out from here.
make a variable called xvprev

key down->right
xvelocity++;
xvprev=xvelocity;

draw actor->
if(xvelocity!=xvprev)
var1=1;
else
var1=0;

I'm kinda tired here, so if this doesn't work tell me and i'll think better tomarrow :)

Re: Help with script

PostPosted: Tue Oct 27, 2009 6:35 am
by DST
draw actor:
Code: Select all
int var=0;
if(xprev!=xvelocity){
//action here;
}
xprev=xvelocity;


gets rid of the 'else' part.

Re: Help with script

PostPosted: Tue Oct 27, 2009 3:45 pm
by Zehper48
jimmy, there isnt a keydown event its all in the draw actor if possible, and DST i tried your code
but i got this error, im kinda noobie so im not sure what to do,

unexpected declairation of xvelocity

Re: Help with script

PostPosted: Tue Oct 27, 2009 9:51 pm
by DST
First, you should make the xprev variable in the variables tab, if you haven't already done so.
Secondly, local variables must be declared at the start of the script. Here, I write var1 as local, but if you'll need to get it from another script, then make it in the variables tab too, and leave out the 'int' part at the beginning.

Then the script should be as follows:
Actor>Draw Actor>
Code: Select all
int var1=0;

if(xprev!=xvelocity){  //if xvelocity has changed since last frame
var1=1;
}

r=255-(var1*255);     //will show you visually if the condition is true, for testing purposes.

xprev=xvelocity;


tested the script, it worked fine. The actor should turn green whenever xvelocity changes.
Note that the scripts run, then output the display frame. They calculate everything in order too. This means that the final output values from all the script are what will be displayed, and these are what will enter the next frame.
This is why xprev=xvelocity is at the end, and also why int var1=0; comes at the beginning.

var1 is local here, and will disappear at the end of the script. If you want to check var1 from any other event, you will have to make it a normal variable like xprev.

Make sure to make xprev a 'real' (float) type variable, because xvelocity is also a real. (as opposed to int or string). Xprev cannot be local because we need the value of the previous frame. That's why you have to create it in the variables tab.

Re: Help with script

PostPosted: Wed Oct 28, 2009 6:46 pm
by Zehper48
SWeeet it works =) thanks to everybody who helped me, and thank you DST your a fking genious =)
your really helpful