Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
  #2  
Old 03-16-2018, 11:32 AM
Kamaeru Kamaeru is offline
G2k1
Kamaeru's Avatar
Join Date: Dec 2001
Posts: 1,040
Kamaeru has much to be proud ofKamaeru has much to be proud ofKamaeru has much to be proud ofKamaeru has much to be proud ofKamaeru has much to be proud ofKamaeru has much to be proud of
Quote:
Originally Posted by fowlplay4 View Post
the code would work exactly the same with a regular timeout
That's what I was thinking but as a noob coder I wasn't going to say it
__________________
3DS friendcode: 1118-0226-7975
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:11 AM.


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