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 07-18-2013, 08:05 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
alternative to sleep()

Is there an alternative function instead of doing let's say this:

Graal Script 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
Reply With Quote
  #2  
Old 07-18-2013, 09:04 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
schedulevent
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #3  
Old 07-18-2013, 09:52 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by Tricxta View Post
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:

Graal Script Code:
function this(){
 if (
check something){
  function 
that();
}

Can you do that?
Reply With Quote
  #4  
Old 07-18-2013, 10:04 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
An alternative to what you're doing in your OP is to use a for() loop

Graal Script Code:
temp.chatArray = {
  
"First""Second""Third"
};

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

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

Reply With Quote
  #5  
Old 07-18-2013, 11:46 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
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.

Graal Script 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.
__________________
Deep into the Darkness peering...
Reply With Quote
  #6  
Old 07-18-2013, 11:49 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by i8bit View Post
Graal Script Code:
function this(){
 if (
check something){
  function 
that();
}

Graal Script 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
__________________
MEEP!
Reply With Quote
  #7  
Old 07-18-2013, 05:26 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Either use a scheduleEvent or a timeout.

Quote:
Originally Posted by Emera View Post
Graal Script 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.
__________________
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 07:14 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.