Optimize a very small script - turning an arrow

Started by TheMagician, Tue 07/06/2005 19:29:52

Previous topic - Next topic

TheMagician

Hi everybody.

Let's say I have an object showing an arrow which can point in four directions: up, right, down, and left.
When the arrow points up and the player clicks on it the arrow jumps to the right. If the player clicks again it points down, then left and the back up again and so on (the player can click on it as often as he/she wants).
I use 4 frames in one loop of one view for the graphics of the arrow.

I know how to script that, but my question is:
is there a way to put the complete routine (turning of the arrow when you click on it) into one single script line?


Right now I have:

user clicks on arrow {
if ( Arrow points up) { change frame to next frame }
else if ( Arrow points right) { change frame to next frame }
else if ( Arrow points down) { change frame to next frame }
else if ( Arrow points left) { change frame BACK TO FIRST frame of of the loop }
}

My question:
is there a way to make the script smaller? Like:

user clicks on arrow {
change frame to "current frame" + 1;
}

The problem in the above script is the point were the arrow has to jump back to the first position.

I hope you understood the problem.  :)
Any ideas and comments are appreciated!

Thanks in advance,
Stefan

Pumaman

Something like this would work:

frame++;
if (frame > 3) frame = 0;

obviously the actual script would depend on what you're doing specifically.

TheMagician


TheMagician

#3
Ok, I have a small problem when it comes to realizing this script:

Is there a way to check which FRAME in a loop an object is currently set to?
I know you can check the current view of an object, but I couldn't find anything about frames in the help file.

Or do I have to assign a variable to the object keeping track of the current direction?

---

And one more general question:
Is there a way to actually script the "interact with hotspot" function right into the room script file without using the hotspot interaction editor?

Thanks in advance,
Stefan

SMF spam blocked by CleanTalk