Help with script

Non-platform specific questions.

Help with script

Postby Zehper48 » Mon Oct 26, 2009 2:08 pm

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
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Help with script

Postby Bee-Ant » Mon Oct 26, 2009 2:27 pm

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;
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Help with script

Postby Zehper48 » Mon Oct 26, 2009 9:44 pm

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?
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Help with script

Postby Bee-Ant » Tue Oct 27, 2009 12:28 am

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
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Help with script

Postby jimmynewguy » Tue Oct 27, 2009 12:44 am

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 :)
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Help with script

Postby DST » Tue Oct 27, 2009 6:35 am

draw actor:
Code: Select all
int var=0;
if(xprev!=xvelocity){
//action here;
}
xprev=xvelocity;


gets rid of the 'else' part.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Help with script

Postby Zehper48 » Tue Oct 27, 2009 3:45 pm

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
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Help with script

Postby DST » Tue Oct 27, 2009 9:51 pm

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Help with script

Postby Zehper48 » Wed Oct 28, 2009 6:46 pm

SWeeet it works =) thanks to everybody who helped me, and thank you DST your a fking genious =)
your really helpful
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron