Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Thu 28/01/2021 15:38:10

Title: Iterate all "elements" in a room
Post by: fratello Manu on Thu 28/01/2021 15:38:10
Hi everyone! I couldn't find an answer... I need to iterate all elements of current room, to display their descriptions somewhere.
I'd like to do this for every character, object and hotspot (let's pretend, to display names in a Label)

So I need something like:

Code (ags) Select
String result = "this room contains: ";

for (every hotspot in room.hotspots)
{
  result = result.Append(hotspot.Description);
  result = result.Append(", ");
}

for (every character in room.characters)
{
  result = result.Append(character.RealName);
  result = result.Append(", ");
}

for (every object in room.objects)
{
  result = result.Append(object.Description);
  result = result.Append(", ");
}


Does someone know if there's a way to do this?

Thanks!
Have a nice day
Title: Re: Iterate all "elements" in a room
Post by: Crimson Wizard on Thu 28/01/2021 16:21:25
Code (ags) Select

for (int i = 0; i < AGS_MAX_HOTSPOTS; i++)
{
    Hotspot* h = hotspot[i];
    // do something
}

for (int i = 0; i < Room.ObjectCount; i++)
{
    Object* o = object[i];
    // do something
}

for (int i = 0; i < Game.CharacterCount; i++)
{
    Character* c = character[i];
    if (c.Room == player.Room)
    {
        // do something
    }
}
Title: Re: Iterate all "elements" in a room
Post by: fratello Manu on Thu 28/01/2021 16:29:09
Amazing!! thanks!