Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-24-2007, 11:59 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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()
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #2  
Old 02-25-2007, 12:02 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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
__________________

Last edited by Kristi; 02-25-2007 at 12:13 AM..
Reply With Quote
  #3  
Old 02-25-2007, 12:08 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
It's clientside.

I only want to delay a weapon effect slightly.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #4  
Old 02-25-2007, 12:13 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by JkWhoSaysNi View Post
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.
__________________
Reply With Quote
  #5  
Old 02-25-2007, 12:26 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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);


__________________

Coming soon (Hopefully:P)
Reply With Quote
  #6  
Old 02-25-2007, 12:44 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Whats the setTimer in your first script after the sleep for? Try to remove it maybe?
Reply With Quote
  #7  
Old 02-25-2007, 12:48 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
That was there because sleep(); disables the timer.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #8  
Old 02-25-2007, 12:53 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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.
__________________
Reply With Quote
  #9  
Old 02-25-2007, 01:08 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #10  
Old 02-25-2007, 01:17 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Yeah the 'sleep' command screws up timeouts, or discontinues them until the sleep is over
Reply With Quote
  #11  
Old 02-25-2007, 03:01 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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).
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:06 AM.


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