Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Feature request (https://forums.graalonline.com/forums/forumdisplay.php?f=194)
-   -   SetTimer<#>(<#>); (https://forums.graalonline.com/forums/showthread.php?t=134259030)

Jiroxys7 05-03-2010 09:49 PM

SetTimer<#>(<#>);
 
Examples: SetTimer1(0.05); SetTimer2(1); SetTimer3(this.timer); etc.

then either something like this:
PHP Code:

function onTimeout1(){blahblah;}
function 
onTimeout2(){blahblah;}
function 
onTimeout3(){blahblah;} 

etc.

or something like this:
PHP Code:

function onTimeout(1){blahblah;}
function 
onTimeout(2){blahblah;}
function 
onTimeout(3){blahblah;} 

whichever works. setTimer(); would still be usable.
unless someone knows a better way to do this already, i've often found myself splitting up weapons into multiple weapons because i couldnt redefine onTimeout in one if(){;} and have another in an elseif(){;} (example, having my jump script change itself to a gravity script if the level is a sidescrolling level. but i couldnt do that so now i have a jump script that disables itself if its a sidescrolling level and a gravity script that activates if its a sidescrolling level. which seems like more than i needed to have.)

then, whenever i need multiple timers and cant split up the script, i also find myself doing something crude like this:

PHP Code:

function onTimeout(){

   if(
this.timer1 >= 0.05){
      
this.timer1 -= 0.05;
    }
     else {
this.timer1 1;}

   if(
this.timer2 >= 0.05){
      
this.timer2 -= 0.05;
    }
     else {
this.timer2 0.5;}

}

setTimer(0.05); 

!pissed!

Inverness 05-03-2010 10:00 PM

First of all, nothing should go outside of function definitions (brackets).

There is also scheduleevent(time, eventname, params...).

So if you do scheduleevent(1, "Pancake", null), then function onPancake() will be called in one second. I imagine this is not quite as efficient as a timeout, so use the timeout for stuff that is 0.05.

Edit:

Also your script should have been looping at 0.5 since that is the smallest timer rather than 0.05.

DustyPorViva 05-03-2010 10:02 PM

If you wanna do what you were asking for:

scheduleevent(timer, "Timeout1", null);

Inverness 05-03-2010 10:04 PM

Quote:

Originally Posted by DustyPorViva (Post 1573875)
If you wanna do what you were asking for:

scheduleevent(timer, "Timeout1", null);

Yep, example:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeout1();
}
function 
onTimeout1() {
  
// do stuff
  
scheduleevent(1"Timeout1"null);


I tend to avoid calling event functions directly though.

WhiteDragon 05-03-2010 10:06 PM

Quote:

Originally Posted by Inverness (Post 1573876)
I tend to avoid calling event functions directly though.

Proper way to stay in the event model would be
PHP Code:

this.trigger("Timeout1"null); 


Jiroxys7 05-03-2010 11:43 PM

Woah. a lot of interesting stuff here. thanks guys, I'll play around with them and see if i cant figure them out :D


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

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