Create a Tween for a Group Object

Hi guys.

Currently trying to create a character collection game.
All of the unlockable characters are part of a global object group and all of them are displayed at a character selection scene.

Below image for example, graphic assets are not final

As you can already guess, once you select a character the blue box tweens and changes its position to the selected character. I managed to do that already.

Now for my issue.
The game supposedly saves your last selected character into the memory.
I want when you restart the game to have the box automatically move to the last selected character (From the previous session)

The thing is, I have no idea how to do this without bloating the code. Like adding the box position action for each character (I plan to add more than 100 characters)

Is there an expression that allows the box to tween at a certain object of your group by reading the variable of it? I know that I can use the below example to create a character from the group for a new scene. Can I do the same in order to automatically tween the movement?

Creating the selected character to the new scene (Succes)

Trying to move the box of the selected character using only one action (Fail, it automatically moves to the last object of the group (The one-eyed monster))

Sorry if I explained this poorly

There’s something not right with those actions. You’re reading from local storage into the scene variable SelectedHeroLocal. But then in the next line you’re setting SelectedLocalHero to a global variable. I think you should be trying it the other way round - set the global variable to the value of the scene variable.

In the code snippet, there’s nothing to specify which hero to move the Select object to. So GDevelop will move it to the (usually) first one you placed on the scene.

Your best move will be to add a Repeat for each Heroes as a subevent to the beginning of scene event, with the condition that compares 2 strings - that Heroes.ObjectName() = SelectedHeroLocal. The action for this event should be the tweening of the select object’s position action.

1 Like

Hi thanks for replying, I am not sure how to do the thing you mentioned :fearful:

This is my whole code for the page right now. If it’s possible can you explain again what I should do? I have a feeling that this is really easy to do but I seem to lack experience and knowledge.

Right now my game works fine. I select a character and the tween happens. When I leave the scene the character is selected and can be used in other scenes.

Now I just need the box to go behind the selected character when you return to the selection scene which I have no idea how to do without adding another code line for each individual character


Assets (Global group consists of Digital heroes)

Never mind I managed to make it work. It seems a bit weird but at least it works.
If you can offer a simpler solution I wouldn’t mind :laughing:

Those second event’s actions - saving the co-ordinates to storage - are being run every single frame. Don’t do that. Instead, put it under a conditional event. Constantly checking storage will affect game performance.

However, I’d do something like the following. Note, it hasn’t been tested:

1 Like