Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   if (timeout) (https://forums.graalonline.com/forums/showthread.php?t=85288)

Schetti 04-24-2009 01:20 PM

if (timeout)
 
PHP Code:

function onBla() {
if (
timeout) {
bla!
 }


why this isnt working?
for example:
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
 if (
player.chat == "Test") {
  
onTestTime();
  
settimer(0.05);
 }
}

function 
onTimeout() {
settimer(.05);
}

function 
onTestTime() {
  
sendtorc("works?");
 if (
timeout) {
  
settimer(.05);
  
sendtorc("timeout?");
 }
  
onTestTime();
  
settimer(0.05);


I know, the script itself is useless, but it MUST have a timeout, doesnt it? So, it sends the "works?" like a spam, but NO "timeout?"

someone can explain why?

Chompy 04-24-2009 02:25 PM

if (timeout) {}

equals

function onTimeout() {}

when using the timeout event

Schetti 04-24-2009 03:37 PM

I know that, but I am wondering why if (timeout) {} isnt working

xXziroXx 04-24-2009 03:50 PM

Quote:

Originally Posted by Schetti (Post 1486474)
I know that, but I am wondering why if (timeout) {} isnt working

Because...


1) You're overwriting it with function onTimeOut()

2) You shouldn't place events inside other events. Even though GS1 allowed it for the most part, it's really bad practice.

Loriel 04-24-2009 04:04 PM

Quote:

Originally Posted by Schetti (Post 1486458)
I know, the script itself is useless, but it MUST have a timeout, doesnt it? So, it sends the "works?" like a spam, but NO "timeout?"

someone can explain why?

onTestTime gets first executed without a timeout set, so there is no chance that "if (timeout)" is true at that point. So the settimer inside the if-block is not being executed either. Consequently the recursive call to onTestTime also happens without a timeout being active, and we basically start from the beginning over and over again until you run out of stack space and the recursion terminates. At that point, the script might either error out or go to the next statement, not sure. If the latter is the case, you will finally set your timer and onTimeout() will be called 0.05 seconds later, setting the timer again and continuing the timeout loop. Since onTimeout is not calling onTestTime, your "if (timeout)" check is not going to be executed anymore and the sendtorc still does not happen.

Your expectation that something different happens implies that you think there is some magic going on that is not actually there.


All times are GMT +2. The time now is 12:47 PM.

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