View Single Post
  #4  
Old 03-13-2018, 04:07 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
there's nothing wrong with using a regular timeout.

polling (timeout, scheduleevent) is what's to be avoided if there's an applicable event (onplayerenters, onplayerhit, etc.) that can eliminate the need for a constantly running script.

the code would work exactly the same with a regular timeout!!!! unless u want to make inefficient baddies that tick every <0.05 sec.

PHP Code:
function onPlayerEnters() {
  
setTimer(this.aiPeriod);
}

function 
onTimeout() {
  if (
players.size() <= 0)
    return;
  
ai_execute();

  
setTimer(this.aiPeriod);
}

function 
enterState(temp.state) {
  if (
this.("ai_enter_"temp.state) != nil)
    
this.("ai_enter_"temp.state)();
}

function 
executeState(temp.state) {
  if (
this.("ai_execute_"temp.state) != nil)
    
this.("ai_execute_"temp.state)();
}

function 
exitState(temp.state) {
  if (
this.("ai_exit_"temp.state) != nil)
    
this.("ai_exit_"temp.state)();
}

function 
changeState(temp.state) {
  if (
this.currentState == temp.state) return;

  
this.exitState(this.currentState);

  
this.previousState this.currentState;
  
this.currentState temp.state;

  
this.enterState(this.currentState);

  
setTimer(this.aiPeriod);
}

function 
ai_execute() {
  
this.executeState(this.globalState);
  
this.executeState(this.currentState);

__________________
Quote:
Reply With Quote