To stop a x x moving script.

Posted:
Tue May 30, 2006 4:44 pm
by Diana Kennedy
Inaugurating this Forum - I hope with no too stupid question. I am relating to my other problem, and this may be the key:
I use the following script in the draw actor event to make an actor move:
- Code: Select all
x = x - 5;
or:
- Code: Select all
x = x + 5;
Now how can I make stop him?
I did this: On a timer event I put:
- Code: Select all
x = x - 0;
But it did not work.

Posted:
Tue May 30, 2006 5:26 pm
by plinydogg
Diana,
I'm not sure exactly what your needs are, but couldn't you
(1) Create a global integer variable called, say, actorCanMove and set it to 0;
(2) In the draw actor event replace x = x - 5 with
if(actorCanMove == 1)
{
x = x-5;
}
(3) When you want the actor to move, set actorCanMove equal to 1; when you want the actor to stop, set actorCanMove equal to 0 again.

Posted:
Tue May 30, 2006 5:53 pm
by Diana Kennedy
Hi Plinydog,
Sounds like a good solution. But I am not advanced enough to know the exact steps to do: I created the variable in the global script editor, but how do I set its value to 0 and what would be the exact syntax?

Posted:
Tue May 30, 2006 7:40 pm
by BeyondtheTech
Just so you know, standard C syntax like
- Code: Select all
x+=5;
is a viable shortcut to
- Code: Select all
x=x+5;
in Game Editor. It's easier to type, less prone to typographical error, and may be ever-so-slightly faster in execution.
x-=5; is the same as x=x-5; and so on...

Posted:
Tue May 30, 2006 7:43 pm
by BeyondtheTech
Another solution is to have the Draw Actor event to have
- Code: Select all
x=x+xmovement;
where xmovement is a variable you can set to 5, -5, 0, or whatever you need to. If you want to stop it, set xmovement to 0. If you need to start up again, set the variable as necessary.

Posted:
Tue May 30, 2006 8:09 pm
by Diana Kennedy
Interesting shortcut thanks.
But I still need to know how to create the variable with the initial setting. I am afraid I don't see clear enough to do this.
[/code]

Posted:
Tue May 30, 2006 9:45 pm
by Novice
To add an initial setting to a variable put
- Code: Select all
variable=any number;
in a create actor event or any other event that ocurs only once (you don't want them to reset each time the event reocurs

)

Posted:
Tue Nov 28, 2006 1:24 am
by Game A Gogo
on create actor insted of draw actor
- Code: Select all
xvelocity=1;
and on the timer thing
- Code: Select all
xvelocity=0;