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.