Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2006, 12:51 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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?

Last edited by jake13jake; 04-25-2006 at 01:58 AM..
Reply With Quote
  #2  
Old 04-25-2006, 05:15 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
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 
Reply With Quote
  #3  
Old 04-25-2006, 10:25 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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.
Reply With Quote
  #4  
Old 04-25-2006, 10:49 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #5  
Old 04-25-2006, 12:10 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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)
Reply With Quote
  #6  
Old 04-25-2006, 02:17 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #7  
Old 04-26-2006, 01:25 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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).
Reply With Quote
Reply


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 12:26 AM.


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