Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   execution of the sleep command (https://forums.graalonline.com/forums/showthread.php?t=65631)

jake13jake 04-25-2006 12:51 AM

execution of the sleep command
 
I am trying to rescript parts of my action system. It currently runs on timeouts, but I'm trying to separate it into functions that I can put into the main part of my movement system (I know there are bugs in this version of the function, but unrelated).

I have:
PHP Code:

public function attemptJump() {
  if (
testJump(NULL)) {
    
this.jump_initx player.x;
    
this.jump_inity player.y;
    
this.jump_a     2*(this.jump_dy-this.jump_v*this.jumpDestMax)/this.jumpDestMax^2;
    
this.jump_v     = -1.25 ;
    
play("jump.wav");
    while (
this.jumpDestCounter this.jumpDestMax) {
      
this.jump_v += this.jump_a;
      
player.x    += this.jump_dx/clientr.movement_jumptime*0.05;
      
player.y    += this.jump_v;
      
drawJumpShadow(true);
      
this.jumpDestCounter++;
      
player.chat this.jumpDestCounter;
      
sleep(0.05);
    }
    
drawJumpShadow(false);
    
player.this.jump_initx this.jump_dx;
    
player.this.jump_inity this.jump_dy;
    
system_gani.updateAni();
    
this.jumpDestCounter 0;
    return 
true;
  }
  return 
false;


On the first execution of the function:
the while-sleep loop continues, but all other scripts also continue.
On subsequent executions it only executes one iteration.

The setTimer in the movement NPC isn't being set until after all script execution is completed in the timeout loop.

movement system calls attemptAction(), attemptAction() calls attemptJump()

This is quite nasty I think. Why shouldn't I be able to delay stack execution within a timeout?

Yen 04-25-2006 05:15 AM

I don't totally understand, but are you looking for..

PHP Code:

  scheduleevent(floatstrparams...) - returns object invokes an event (onEventnameafter the specified delay (in seconds), second parameter is the event namefollowed by the parameters 


jake13jake 04-25-2006 10:25 AM

I'm trying to delay script execution on the stack.

meaning

Stack:
attemptJump--interior execution in a while-sleep loop, shouldn't return until the while-sleep loop has executed (the problem is that it does, or only runs through one iteration of while).
attemptAction--waits for attemptJump execution until it returns
movement main--waits for attemptAction to return until continuing other script executions.

Admins 04-25-2006 10:49 AM

Actually I have never tried to use sleep() in a function called by another object, so I can imagine that there are problems. Designing the program to not rely on blocking functions would be better in the long way.

jake13jake 04-25-2006 12:10 PM

Quote:

Originally Posted by Stefan
Actually I have never tried to use sleep() in a function called by another object, so I can imagine that there are problems. Designing the program to not rely on blocking functions would be better in the long way.

It would be pretty nasty w/o this type of implementation imo, I'd have to check for movement freezes and redirect all script execution somewhere else. I'd say overall it's much better for readability and maneuverability the way I'm trying to setup movement overall for the loop to delay stack execution. Maybe it's just a problem that public functions have, but can't test it now, I've been up all night. If worse comes to worst I can always temporarily store the action system's functions directly into the movement NPC.

Is it a problem with adding public functions to the stack? (I'd suspect it is)

Admins 04-25-2006 02:17 PM

By design i mean you make the functionality before and after the attempted jump independent. I meant its better to do that in the long way because you also might depend on some serverside action or similar.
The sleep in an external script is having problems because it would need to store the state of several virtual machines. It's probably possible but slightly more complex.

jake13jake 04-26-2006 01:25 AM

Quote:

Originally Posted by Stefan
By design i mean you make the functionality before and after the attempted jump independent. I meant its better to do that in the long way because you also might depend on some serverside action or similar.
The sleep in an external script is having problems because it would need to store the state of several virtual machines. It's probably possible but slightly more complex.

Maneuverability is still pretty much my largest goal, keeping in mind that a large number of scripts might want to modify movement in different ways. So, I might try classing up the action functions rather than keeping them in a separate NPC (I'll see how that works).


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

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