How to edit variables via group, then show in txt?

Is there a way to edit variables via a group? I am trying to have all my character skins level up their stats with the click of one button and I am doing this by having them in a group. But it doesn’t seem to be working. Is this what the code should look like?

Based on the info here, can’t you just change multiple variables at the same time?

Yes, but its not ideal.
If I did, then every update that adds characters I’d have to update this function. If i can just add them to a group, then that’s much easier.

What is the text object ArmorPercent? Is that one object or is there an instance for each object?

You might need to use for each object and if there are separate text objects, you would need to pick the matching objects. With a condition like take into account linked objects or is stuck to another object if you’re using the sticker behavior. Or some other condition.

Edit: does each knight have gold or just a main gold variable? Maybe, you need to use an object variable.

I don’t think we have enough info. We’re doing too much guessing.

The text object is just the UI element. Its a scene object.

Gold is a global variable, which currently doesnt interact with the knight code itself.

Basically i want to be able to click a button in my army designer screen, to buff all my knights in a group, and subtract gold which is the games global currency.

Does that make sense?

What is it currently doing? Is it subtracting the gold?

The title is " edit variables via group" which variables are you trying to edit and in what way.

If you put objects into a group then you can use the group name to do anytime that you can do by using the object name. It’s just a reference.

If the objects are a, b and c. And the group is players then you use players.variableName and it changes a, b and c to the same value. You might need to use a for each object depending on the events and the value.

So editing the gold currently works just fine. It’s editing the armor flat reduction variable from the knights group that doesnt work. Then the txt isnt reflecting the change, but i think that’s because the group knights flat damage reduction isnt changing.

Okay and with players: Maybe I’ve missed something, can i add a player status to a sprite somehow?

The value should be updating unless it’s being set to another value somewhere else.

Note: The value is being increased on all of the knights by a point. If they’re created at different times they’ll have different values. If you’re using 1 text object it will display the value of the knight object that was created the earliest.

You can use a separate text object or health bar for each object. You can use the sticker behavior and pick the matching text object with the stickers is stuck to condition.

Knights in collision with…
Apply damage
For each knjght
— text is stuck to knight set text to value

The knights are global objects but they’re not spanwed in in this scene.

Do i need to make a global variable to change and update their stats from that when they spawn in?

You can’t change an object that doesn’t exist in the scene you’re in even if they’re global. A global object just means it can be added to any scene. They still behave like a regular object.

So, yes. You can use a global variable and then change the objects property when it’s created or if they’re in another scene that you go back to, they would have to be updated there.

Okay thats what I was missing. Thanks so much for your help!!

1 Like