![]() |
Looping
How do you make something loop. For instance.
if (playerenters) { hide; sleep 2; show; sleep 2; } How would i loop it? Thanks. =] |
use timeout
|
yes but could you help me out. I'm trying that, but i can't get it to work.
|
Re: Looping
Quote:
NPC Code: I will have timeouts in my script guide soon |
thanks
|
Have you ever heard of timeout you complete *****. There is also while, which to loop that you could try sleep or break, but the falg you are using while with must be true for it to loop...
|
timeout is easy
but while wouldnt work the way he done it while (playerenters) just doesnt work |
Very True. while isnt the best thing to use when using a script. You would have to set a flag and then use while (flagname) {script here; } and when you dont want it to loop any more unset the flagname.
|
Re: Looping
Quote:
//#CLIENTSIDE if (playerenters){ timeout=.05; } //#CLIENTSIDE while (timeout){ hide; sleep2; show; sleep .10; } |
Re: Re: Looping
Quote:
|
timeout isnt a constant flag is set to true once only the moment it gets to 0 so a while loop with timeout wouldnt work
|
if (playerenters) timeout = .05;
if (timeout) { if (visible) hide; else show; timeout = 2; } |
hmm
if possible, you want to stay away from sleep variables, because that stops everything in the NPC until the sleep is over. Try using something like this.sleep like this:
if (playerenters) {timeout = .1; show; this.sleep=20; this.on=1; } if (timeout) { if (this.sleep>0) {this.sleep-=1; } if (this.sleep<=0) {this.sleep=20; if (this.on=1) {this.on=0; hide; } if (this.on=0) {this.on=1; show; } } timeout = .1; } That will make it so other flags can be unset/set while the sleep counter is going. If all you want to do in the npc is hide and show for some reason, use one of the previous scripts, other wise, if you have a lot of sleeping required, use this.vars so things are timed correctly. also, since timeout is equal to 1/10th of a second, this.sleep=20 would wait 2 seconds, and then change. if the timeout was equal to .05 you might want to use 40 for this.sleep. That about wraps it up. |
you could use:
NPC Code: or, you could go for the less convenient option... NPC Code: But the second is pointless. Use the first. |
oye...why must idiots insult people who can't script as well as them and haven't done anything to deserve harsh words?
anyway... timeout loops NPC Code: Timeout will make the timeout counter count down to 0 if you set it to anything above 0, and when it gets to 0, it will trigger a flag called timeout on the npc. If you place a timeout at the end of an if (timeout) statement, then it will loop. while loops NPC Code: While is just like if, except when it finds a } it will go back to the while () and check the statement again. If the conditions in the brackets are still true, it will do the loop again. Otherwise, it will jump back to the } and continue with the script. Above, I have while (1==1), which will create an infinite loop. for loops NPC Code: For is very useful, and most loops you encounter (that aren't timeout loops) will use for. If you have read the commands.rtf, you should notice that the syntax for for is something like: for (initial; condition; increment) { Now, the loop above could be written like this, and work the same way: NPC Code: And, if you look at the debugger while playing (F6), you'll notice that your for loops are changed into while loops when they're processed by the scripting engine. The reason you use for though is because it's much easier to write, and is harder to mess up with. The best advantage with for loops is that you can use the variable that is looping in your scripting. So, you could loop through an entire array and add all the numbers like this: NPC Code: Now, I'll assume you don't know arrays since you're asking about loops, but just remember that loops can be very useful with arrays when you get to them. |
Quote:
|
Damn Kyle your good.
|
ummmm...
actually when it hits 0 it becomes true until a timeout is set again meaning this:
NPC Code: would work... |
Oh I see thanks
|
Quote:
flag just means an event to call it. NPC Code: is same as [code] while (i=0;i<10;i++;){ commands; } [/codes] its just a lengthier version :) same as NPC Code: same as NPC Code: |
Not every flag triggers an NPC...in fact, many don't. If you callnpc it will though.
|
ohh and if he did not know:
NPC Code: :D |
Quote:
|
How the hell did you guys learn to script I suck and then your all here putting leet scripts all over forums. I feel so inferior
|
| All times are GMT +2. The time now is 07:56 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.