Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Sat 23/05/2009 19:32:10

Title: Doing things to *every* index in an array...
Post by: Technocrat on Sat 23/05/2009 19:32:10
Hopefully this is a "basic" question rather than an "advanced" one. I'll see if I can explain this one more clearly...

I have an array (int growth[10]; ), and within each of the indexes the number will represent the stage of growth a plant that each index refers to is at. When the player moves on to the next "day", the value of the indexes need to increase by one.

If there are different values in each index of the array, firstly: is there a way to increase *every* index by one, rather than manually going through each in the script? Something to make every index in the growth array go up by one?

Secondly, is there a way to make the value increase based on what the value in the index was before? For example, "if growth[2] == 50;" set it to 7 in the script - except to run this for every single index in the array, once again, without having to tell it to do it manually to each index of it.

Hopefully that's clear enough!
Title: Re: Doing things to *every* index in an array...
Post by: GarageGothic on Sat 23/05/2009 19:36:53
Use a while loop to run through the array:

int counter;
while (counter < 10) {
  growth[counter] = growth[counter]+1;
  if (growth[counter] == 50) growth[counter] = 7;
  counter++;
  }