 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
a person Guest
|
Posted: Wed Feb 11, 2004 9:15 am Post subject: Need help with a for loop/while loop |
|
|
Here's the deal. I made this script that works. If you press the left key, an NPC walks left, right key, the NPC walks right, but I had it set as when key is pressed script.
NOW I am trying to implement it into a forever loop so I can have other things happen (like your guy animate while not walking and such). But when I put on the while loop like so:
while (play==true) do (# this is the NPC walking stuff, which works #)
It doesn't lett me push the keys and make the NPC walk. Why does this happen?
Is there a way I can make a forever loop that'll allow the player to still push keys and such?
I tried doing a for loop like this:
for (play,10,0,0) do(# NPC stuff)
But it still didn't work, same problem. Why?
please help because it is really annoying!!!!!!  |
|
Back to top |
|
 |
Cube Dimensional Traveller

Joined: 02 Feb 2003 Posts: 294
|
Posted: Wed Feb 11, 2004 11:44 am Post subject: |
|
|
For loops aren't exactly what you'd want to use for something like this, so I'll just do the while loop . So, here's how it ought to work:
Code: | while(play==true) do (
wait for npc (#)
if (key is pressed(key:right) then (
walk npc (#, right, 5)
)
if (key is pressed(key:left) then (
walk npc (#, left, 5)
)
wait(1)
)
|
This may or may not be similar to what you have made yourself, but there's a good chance you just left out the wait(1). You need that or the OHR loops too fast and just well... Stops.
So try that, and see how it goes. Post again if you get any trouble with this script or any others . |
|
Back to top |
|
 |
T-Master
Joined: 10 Dec 2003 Posts: 74
|
Posted: Wed Feb 11, 2004 1:55 pm Post subject: |
|
|
You might want to include a break condition in that. |
|
Back to top |
|
 |
Cube Dimensional Traveller

Joined: 02 Feb 2003 Posts: 294
|
Posted: Wed Feb 11, 2004 4:07 pm Post subject: |
|
|
Oh, well yeah. Of course, the break doesn't nessisarily need to be in the loop itself of course... Just somewhere... Anywhere. Considering he did the condition for the loop argument correctly I'd have to assume he knew that already . |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Wed Feb 11, 2004 10:40 pm Post subject: |
|
|
If you wrote
for (play,10,0,0) do(# NPC stuff)
in your script, when it is run the HS interpreter will simply skip over it, so that won't work.
Yes, you see, the reason you need a wait command is that every time game.exe comes across a wait command, it takes a break from running scripts and does everything else, for example checking what keys are pressed, moving npcs and updating. Without it, game will smply run your while loop for ever, and will never ever refresh the screen. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
a person Guest
|
Posted: Thu Feb 12, 2004 7:29 am Post subject: thanks! |
|
|
Yeah, thanks, I couldn't quite understand it. I thought that the plotscipt, when it came to a "if key is pressed" command it would the check to see if it is pressed at that time. Thanks alot.  |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|