Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   alternative to sleep() (https://forums.graalonline.com/forums/showthread.php?t=134268483)

i8bit 07-18-2013 07:05 AM

alternative to sleep()
 
Is there an alternative function instead of doing let's say this:

PHP Code:

function onCreated(){
 
this.chat "Set 1";
 
sleep(1);
 
this.chat "Set 2";
 
sleep(1);
 
this.chat "Set 3";
 
sleep(1);
 
this.chat "Set 3";


I'm scripting a baddie and I have an attack skill that does multiple damage functions set up similar to what's above. But my baddie glitches in weird ways when ever I use sleeps() so I was wondering if there were any alternatives to write what I have.

I need an
Action()
Wait(0.2)
Action()
Wait(0.2)
so on

Tricxta 07-18-2013 08:04 AM

schedulevent

i8bit 07-18-2013 08:52 AM

Quote:

Originally Posted by Tricxta (Post 1720752)
schedulevent

I know I could do that but that would mean I would have to come out of my 'checks' to activate a new function...unless you can do functions inside functions?

like:

PHP Code:

function this(){
 if (
check something){
  function 
that();
}


Can you do that?

Emera 07-18-2013 09:04 AM

An alternative to what you're doing in your OP is to use a for() loop

PHP Code:

temp.chatArray = {
  
"First""Second""Third"
};

for (
temp.0temp.3temp.++) {
  
this.chat temp.chatArray[temp.i];

  
//Use waitFor() instead of sleep
  
waitFor(thisthis1);



Angel_Light 07-18-2013 10:46 AM

I suspect you are using a timeout loop. Sleep will stop a timeout loop if a fuction is triggered from an outside function of the loop. Might be able to save some lines if simply add an adding number and either a if-else block, for loop, or a switch statement.

PHP Code:

function onCreated()
{

  
this.chatText = { "Blah0""Blah1""Blah2"}; // For second method

}

function 
onTimeout()
{

  
this.++;
  
//Then either
  
if ( this.== 0Blah0;
  else if ( 
this.== 0Blah1;
  else 
Blah2;
  
// or
  
for ( temp.0temp.3temp.++;)
  {
    
this.chat this.chatTexttemp.i];
    
sleep0.15); // assuming your time out is 0.05
  
}
  
// or finaly
  
switch ( this.i)
  {
    case 
0Blah0; break;
    case 
1Blah1; break;
    case 
2Blah2; break;
  }
  
  

  
setTimer0.05);



Just remember for these method you will have to add the extra sleep( 0.15); within those to extend the waiting for the time out. Which using the sleep in the timeout might be detrimental in what you are trying to do. Using scheduleEvent, catchEvent, or waitfor as Emera demonstrated would be best without breaking or delaying the timeout.

callimuc 07-18-2013 10:49 AM

Quote:

Originally Posted by i8bit (Post 1720753)
PHP Code:

function this(){
 if (
check something){
  function 
that();
}



PHP Code:

function onHello() {
  
temp.toAvoid "somePlayer";
  if (
player.account != temp.toAvoid) {
    
sendGreeting();
  }
}

function 
sendGreeting() {
  
this.chat "HEYYY BUDDY WAZUP";
  echo(
"MY BUDDY IS HERE WOOO");


do you mean something like that? there is no need for having a function inside a function as you can always just trigger another function

cbk1994 07-18-2013 04:26 PM

Either use a scheduleEvent or a timeout.

Quote:

Originally Posted by Emera (Post 1720754)
PHP Code:

//Use waitFor() instead of sleep
  
waitFor(thisthis1); 


This is not an appropriate use of waitFor, plus waitFor suffers from the same issues that sleep does.


All times are GMT +2. The time now is 11:03 PM.

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