Doing things to *every* index in an array...

Started by Technocrat, Sat 23/05/2009 19:32:10

Previous topic - Next topic

Technocrat

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!

GarageGothic

#1
Use a while loop to run through the array:

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

SMF spam blocked by CleanTalk