Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Sleep in timeout... (https://forums.graalonline.com/forums/showthread.php?t=72438)

JkWhoSaysNi 02-24-2007 11:59 PM

Sleep in timeout...
 
Causes strange problems.

I have sleep(0.05); in a quite complicated script. It's actually inside a loop in a timeout.

The problem is, not only does it seem to stop the timeout, it seems to also stop the loop.

heres what I have:

PHP Code:

function onTimeout() {
for(
i=0;i<=20;i++) {
     if (
== 20this.extended true;
     
     if (!
this.extended && (== 0)) {
          
sleep(0.05);
          
setTimer(0.05);

     }
//Code here never gets executed
}
... 

I tried restarting the timer after calling sleep() but the rest of the stuff after sleep(); in the timeout never gets executed.

edit: actually, it is being executed, but for some reason it's not working as it does without the sleep()

Kristi 02-25-2007 12:02 AM

This serversided or clientsided?
I highly do not recommend the sleep command in any instance.

Edit: Not working as it does without the sleep is very vauge. Its hard for me to tell you whats up without seeing the rest of the script

JkWhoSaysNi 02-25-2007 12:08 AM

It's clientside.

I only want to delay a weapon effect slightly.

Kristi 02-25-2007 12:13 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1281805)
It's clientside.

I only want to delay a weapon effect slightly.

Tell me exactly what you are trying to do (and show the script as well). We can come up with a more suitable way for delaying.

JkWhoSaysNi 02-25-2007 12:26 AM

I'm displaying anis that get sequentially further from the player.. I just don't want them all to appear at once, i want them to be visibly appearing one at a time.


Heres the timeout part. I just want the images to visibly show one at a time.

PHP Code:

function onTimeout() {
 if (
keydown(6)) {
 for(
i=0;i<=20;i++) {
 if (
== 20this.extended true;
 if (!
this.extended && (== 0)) {
//Here is where I want the sleep();
    
}


fx = (player.x+2+vecx(player.dir)*i*0.7)-3;
fy = (player.y+1+vecy(player.dir)*i*0.7)-2;


hideimg(i+150);
showani(i+150,fx,fy,0,"fire_scalable",((i*0.05)*random(0.9,1.1)));

if(
== 19) {
        
triggeraction(0,0,"serverside","flamethrower",fx,fy);

     
//    hitobjects(1,fx,fy);
        
}
    
this.lastfx fx;
    
this.lastfy fy;
}


}
else {
  
this.extended false;
  for(
i=1;i<=20;i++) {
    
hideimg(150+i);
  }
}

setTimer(0.05);




Crow 02-25-2007 12:44 AM

Whats the setTimer in your first script after the sleep for? Try to remove it maybe?

JkWhoSaysNi 02-25-2007 12:48 AM

That was there because sleep(); disables the timer.

Kristi 02-25-2007 12:53 AM

Oh boy. What you're attempting to do is either more suited for a gani script or a putnpc for smoothness's sake. But... you need to rethink this in a way that the timeout loop actually loops during the process, not get the whole flame out in one timeout.

This needs to be rethought out. I would suggest particles, or maybe even rotation of image index's, or ganis that resize their own fires to make them look dynamic. Then its just a process of when you initially hold the fire button, the flames progressively shoot out (add one image each timeout), having them reach a point and just let the ganiscripts or particles handle their own effects, and then when you let go of d, just stop the particles or progressively destroy the images 1 by one starting with the one by the flamethrower (take away one each timeout). This can all be done without sleep.

You can break it down, you can have a when fire is pressed, this.flamestart = true. then when its out, this.flaming = true, and then, when flaming is true but firebutton isnt down, start the taking the fire away process.

How you choose to finish it is up to you.

JkWhoSaysNi 02-25-2007 01:08 AM

Thanks. The individual fires are ganis and the effect looks great.


I'll try remaking it so it's not all in 1 timeout and see if I can get it to work like that. The problem is, I have it so you can move while firing, and also have it bouncing off walls.

Rapidwolve 02-25-2007 01:17 AM

Yeah the 'sleep' command screws up timeouts, or discontinues them until the sleep is over

Admins 02-25-2007 03:01 AM

The sleep() command is using timeouts. It doesn't actually require timeouts to work, but if it wouldn't use timeouts then a lot of scripts would break because currently you can easily stop sleeps() by setting timeout to zero. That was some old kind of "cancelevent".

You can however use new ways of suspending the script: waitfor("","noevent", 0.05) (the second parameter is the event name, just set it to some event that is never triggered).


All times are GMT +2. The time now is 05:30 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.