Nested Functions???

You must understand the Game Editor concepts, before post here.

Nested Functions???

Postby plinydogg » Thu Jun 01, 2006 8:24 pm

Sorry about the inadequate label, I'm not even really sure what to call my question(!).

The broad issue is this: if you're iterating through a list of actors and you want to do certain things to each depending on certain variables, and you also need to get some user input for each actor, how do you control the flow?

Specifically, I might have any number of spaceships in the air at once. I also have a function, named checkColonizeAbility(), that checks to see if the ship can colonize a planet (depending on how far away it is, etc.). If the ship can colonize, then the player is prompted to decide whether or not to colonize that planet or move on. There's no problem when there is only one ship that is able to colonize at a time, but if there are more than one, how do I control the flow so that the user can give input for each one?

In code, I've got more or less the following:

void nextTurn()
{
int i; //each i represents a pointer to a ship actor contained in an array
for(i = 0; i < shipCount; i++)
{
if(checkColonizeAbility(i) == 1)
{
colonize();
}
}
}

In other words, I need to somehow suspend execution of the for loop while the player is asked whether or not he wants to colonize. Then, after somehow saving the player's decision, I need to proceed to the next ship (the next i). Does my question make sense? And does anyone have a clue as to how to proceed?

Thanks in advance!
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby makslane » Thu Jun 01, 2006 9:22 pm

You can't get user input while is in a script execution.

I think you can call the nextTurn() function in a 'Draw Actor' event, but you need stop, if the check is true:

Code: Select all
void nextTurn()
{
  int i; //each i represents a pointer to a ship actor contained in an array
  for(i = 0; i < shipCount; i++)
  {
    if(checkColonizeAbility(i) == 1)
    {
      colonize();
      return; //stop the loop here
    }
  }
}



I think a more light way it's call the colonize() function when each actor detect the Colonize Ability, so, you can avoid the time spent in the nextTurn loop. Works for you?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby plinydogg » Thu Jun 01, 2006 10:01 pm

Sounds good! I'll try it out and report back here if I can't get it to work. Thanks for your speedy help Makslane!
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest