Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Bug Report (https://forums.graalonline.com/forums/forumdisplay.php?f=193)
-   -   keydown and float (https://forums.graalonline.com/forums/showthread.php?t=134264787)

Tolnaftate2004 10-13-2011 04:12 AM

keydown, float, and more.
 
When checking if the direction keys are pressed,
PHP Code:

temp.sum 0;
for (
temp.i: {0,1,2,3})
  
temp.sum += keydown(temp.i);
echo(
temp.sum); 

is always less than or equal to 2. I can understand doing this as an optimization, but can it at least choose to report the keys that do not also have the reverse direction pressed?
e: Nevermind the above. Thanks, Jazz.

Additionally,
PHP Code:

echo(float("0.0")) 

prints -1.

e: Another bug just recently discovered. sleep-like functions are messing up the callstack. The specifics are:
  • the parent caller is a public function
  • the call is to a public function of another object (I've tried both weapon and TStaticVar)
  • the public function contains a sleep-like function. Before the sleep, the callstack correctly contains an entry for the caller, afterwards, it does not
  • script hangs indefinitely

In as terse a script as possible:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.= new TStaticVar();
  
temp.b.= function () { return this.c.a("f"); };
  
temp.b.= new TStaticVar();
  
temp.b.c.= function (b) { sleep(1); return "a" b; };
  
player.chat temp.b.a();
  
/* the below never gets executed */
  
player.chat "?";



oo_jazz_oo 10-13-2011 06:40 AM

As for the keydown thing, thats not a limitation of Graal, thats a limitation of your keyboard.

My keyboard allows me to press left, right, and down at the same time. (So with your script, it = 3)
But I cannot do up/down/left.

However, if I use the num keys, I can do all four directional buttons at once. (The script outputs 4)

So, yeah.

Tolnaftate2004 10-13-2011 08:55 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1670744)
As for the keydown thing, thats not a limitation of Graal, thats a limitation of your keyboard.

My keyboard allows me to press left, right, and down at the same time. (So with your script, it = 3)
But I cannot do up/down/left.

However, if I use the num keys, I can do all four directional buttons at once. (The script outputs 4)

So, yeah.

So it is! I had someone else try on their computer and reported the same problem... oh well. Thanks.

Admins 10-13-2011 10:38 PM

The thing about float(string) is that it's only returning 0 if the string is really "0". That way you can check if it's a number and not a name or so. May be it could also allow "0.0" (but then you complain about 0.0000 i guess :D

I can check the problem with sleep(). The thing is that waitfor() is working fine, so it might be a problem of the sleeping object not being active (some this.trigger("update",""); or so could fix it).

Tolnaftate2004 10-13-2011 10:50 PM

Quote:

Originally Posted by Stefan (Post 1670816)
The thing is that waitfor() is working fine, ...

I actually uncovered this because waitfor exhibits this behavior.

e: The call stack is only severed at the call from script A to script B. The call stack is intact for any function calls within B.

What I have looks like this:

A
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
thing = new TStaticVar();
  
thing.set = function () {
    if (
B.ask("Are you sure?")) {
      
fool_the_DCO 1;
    }
    echo(
"foo"); // never called
  
};
}

function 
onKeyPres$ed() {
  
thing.set();


$ inserted to get around the silly security.

B
PHP Code:

//#CLIENTSIDE
public function ask(text) {
  
temp.resp display(text,{"yes","no"});
  echo(
temp.resp); // echo just fine
  
return temp.resp// call stack severed, never returns
}

function 
display() {
  for (
temp.i=0temp.i<pagestemp.i++) {
    
// ask for player input
    
while (!waitfor(this.name,"onPlayerInput"));
    
temp.some_datum;
  }
  return 
temp.r// returns just fine


Or on Zenkou, pfatest: 432-6, SystemAlerts.

Admins 10-14-2011 12:56 AM

Well in that case it might a problem that your TStaticVar has no name... Would be good to check that. We are using tons of waitfors in other objects (database queries) and never had problems with that.

Tolnaftate2004 10-14-2011 02:39 AM

Quote:

Originally Posted by Stefan (Post 1670845)
Well in that case it might a problem that your TStaticVar has no name... Would be good to check that. We are using tons of waitfors in other objects (database queries) and never had problems with that.

The TStaticVar has a name in the actual code.

e: This mimics exactly the problem I've been having:
PHP Code:

function onCreated() {
  
this.call = function () {
    echo(
"before" SPC getcallstack().size()); // before 3
    
waitfor(this.name,"ignoreme",1); // equivalently, sleep(1);
    
echo("after" SPC getcallstack().size()); // after 1
    
return "test";
  };
  
temp.= new TStaticVar("A");
  
temp.a.call = function (caller) {
    
temp.resp caller.call();
    echo(
temp.resp);
    return 
temp.resp;
  };
  echo(
temp.a.call(this));


However, I think this illustrates an even deeper problem:
PHP Code:

//#CLIENTSIDE

function onCreated() {
  
temp.= new TStaticVar("B");
  
temp.b.call = function () {
    echo(
"before" SPC getcallstack().size()); // before 2
    
sleep(1);
    echo(
"after" SPC getcallstack().size()); // never gets executed...
    
return "test";
  };
  echo(
temp.b.call());



Admins 10-14-2011 08:11 AM

Well this might be more a problem of your use of function pointers, just tried simply to se script classes?

Tolnaftate2004 10-14-2011 05:50 PM

Quote:

Originally Posted by Stefan (Post 1670882)
Well ..., just tried simply to se script classes?

Yes, this fixes the problem, but can nothing be done about sleep and waitfor in an anonymous function? e: Because in fact, the offending sleep in my code is in a regular function in a weapon/GUI, which is called by a public function of that weapon/GUI, and it is still causing the execution to halt within my anon. function. While I can verify that the return within the function is working correctly, the same cannot be said of the public function.

Admins 10-17-2011 10:06 PM

Ok the problem is that a script-less object cannot continue after sleep or waitfors, will be fixed in the next version.

Tolnaftate2004 10-17-2011 10:12 PM

Quote:

Originally Posted by Stefan (Post 1671064)
Ok the problem is that a script-less object cannot continue after sleep or waitfors, will be fixed in the next version.

Great; thank you!

WhiteDragon 10-18-2011 12:19 AM

Nice!


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

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