I can't seem to center text on my buttons automatically

Hi guys, first post here, sorry if I make any mistakes.

I’m making a kind of event-based roguelike town simulator, and there are a lot of buttons I need to make. Up until now I’ve been making each one individually.

And now I’m trying to streamline the process a little. I have already made it so the animation part happens with every button via an external event. (I have made a separate scene just for the button functionality for organizational reasons)

The problem is now I can’t make it so the Text Object that every button has as a label stays in the center of the correct button.

These are my events now. I’ve put some buttons and text in this scene to test, and while I can get the buttons to label themselves correctly, I can’t make them centered in the correct button.

This is the scene. Every button and every object have an object variable called ButtonID that I set manually in the scene. Top one is A for both button and text, and so on.

What I want is for the game to check each text object’s ButtonID and then move its position to the center of the button with the same ButtonID.

Starting the preview now centers the first button, but not the other two.

Any help would be greatly appreciated!

I’ve had to put all images into one, so here it is:

Off the top of my head (untested) I think you should try using a “For each object” loop like this:

Repeat for each instance of EmptyButton:
  The text of variable ButtonID of ButtonText = EmptyButton.VariableString(ButtonID)
    Change the position of ButtonText...
1 Like

It worked!! Thanks a lot man! “For each” events are something I hadn’t used yet. :slight_smile:

1 Like