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
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));
}
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..
You can shorten that code considerably:
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?
all available yes
Ok, so one way is this:
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];
}
}
}
only this? nothing else ?
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.
ok, thanks :smiley: