Thread: Npc to Npc
View Single Post
  #49  
Old 02-18-2011, 08:12 AM
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
If you style your script properly you'll see the following..

PHP Code:
//#CLIENTSIDE
// other code..

function onTimeOut() { 
  if (
players.size() > 0)  // Useless on client-side since script won't run
    
setTimer(0.1);         // if player is in another level.
    
else  
    
setTimer(0);
  
// Loops through all npcs near the switch
  
for (temp.findareanpcs(this.x-2this.y-222)) {
    
// Checks if npc is a bomb
    
if (temp.i.isinclass("bomb")) { // Added the { for clarity
      // Triggers switch
      
SwitchDB.door.(@this.switchid).trigger("DoorOpened"null);
    }
    
// Sleeps for 3.2 seconds
    
sleep(3.2);
    
// Recursively calls onTimeout again, leading to an infinite loop.
    // Without a sleep the script would break quite quickly after hitting
    // the stack/maxloop limit.
    
onTimeOut(); 
  } 

Notice how you're sleeping for every NPC around the switch and then calling onTimeout which causes that nasty loop.

Also something about calling onTimeout directly like that is just unsettling to me, the only time I do that is when I'm hacking around with code.

Recursion crash example:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
recurse(0);
}

function 
recurse(a) {
  echo(
a);
  
recurse(a+1);

That's as big as hint as I'll give you, I'm sure you can figure out what you need to change.
__________________
Quote:

Last edited by fowlplay4; 02-18-2011 at 08:28 AM..
Reply With Quote