Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zeta_san on Fri 14/10/2022 08:09:25

Title: dynamic object list
Post by: zeta_san on Fri 14/10/2022 08:09:25
hi boys

I would like to do one thing, I need a dynamic object list

when the object is visible (true) it appears creating a list

example

if only 1 and 2 are true
the list will be

1
2

if only 5 and 7 are true
the list will be

5
7

I hope I was clear
thank you
Title: Re: dynamic object list
Post by: Khris on Fri 14/10/2022 09:16:10
Depending on the use case you can use an array or a set for this. A Set is easier because it already has methods like .Contains(), however you can only add Strings to it so you would need to convert to a string to store a number and convert it back after reading it from the set.

Here's extender functions that allow storing numbers instead:
bool AddNumber(this Set*, int number) {
  return this.Add(String.Format("%d", number));
}

bool ContainsNumber(this Set*, int number) {
  return this.Contains(String.Format("%d", number)); 
}

bool RemoveNumber(this Set*, int number) {
  return this.Remove(String.Format("%d", number)); 
}
Title: Re: dynamic object list
Post by: zeta_san on Fri 14/10/2022 11:49:38
hi khris

in this case?



if (destinationArtena == true) {
  oTartena.Visible = true;
} else {
  oTartena.Visible = false;
}

if (destinationMilano == true) {
  oTmilano.Visible = true;
} else {
  oTmilano.Visible = false;
}

if (destinationRoma == true) {
  oTroma.Visible = true;
} else {
  oTroma.Visible = false;
}

ecc..
Title: Re: dynamic object list
Post by: Khris on Fri 14/10/2022 12:21:43
You can shorten that code considerably:
Code (ags) Select
  oTartena.Visible = destinationArtena;
  oTmilano.Visible = destinationMilano;
  // etc.

Not sure if you need a set then, but I'm still not sure what you're trying to do exactly.
What do you mean by "creating a list"? Do you want the objects to appear below each other?
Title: Re: dynamic object list
Post by: zeta_san on Fri 14/10/2022 13:59:48
all available yes
Title: Re: dynamic object list
Post by: Khris on Fri 14/10/2022 14:25:25
Ok, so one way is this:
Code (ags) Select
function UpdateDestinations() {
  // topmost position
  int y = 123;
  Object* o;
  // object IDs 0 - 7
  for (int i = 0; i < 8; i++) {
    o = object[i];
    if (o.Visible) {
      o.Y = y;
      y += Game.SpriteHeight[o.Graphic];
    }
  }
}
Title: Re: dynamic object list
Post by: zeta_san on Fri 14/10/2022 15:16:22
only this? nothing else ?
Title: Re: dynamic object list
Post by: Khris on Fri 14/10/2022 15:20:52
I'm sorry but this is getting really frustrating. Can you please explain properly what you're trying to do? I'm just guessing wildly here, trying to assemble a puzzle where half the pieces are missing.
You're talking about a list and you seem to have a bunch of objects which represent destinations but there's no context or useful code whatsoever.

The function I posted above will arrange the visible objects of indices 0 to 7 in a stack at the given y coordinate, so if that's what/all you need, then yes, only this. But I have no way to tell.
Title: Re: dynamic object list
Post by: zeta_san on Fri 14/10/2022 15:24:50
ok, thanks :smiley: