How to call an object using variables

[Sorry if my sentences sound weird, I’m not a native speaker.]
Like the title suggests, how would I call an object using a variable
For example :
The object names are block, slope, and ball
And I want to only move the ball object by changing the variable string to “ball”
But I can’t change its position since the action requires it to be an object
So, is there any way I can do this?
Thanks in advance!

  1. Create a group
  • In the “Object Groups” panel, create a group called AllObjects.
  • Add your objects (block, slope, and ball) to this group.
  1. Create a variable
  • Set a scene variable (I will use : SelectedObject) to “ball” (or “block”, etc).
  1. Use these events:
For each object AllObjects:
    Condition: Compare two strings (there should be an event that does that I believe)
              ObjectName(AllObjects) = VariableString(SelectedObject)
    Action:   Change X position of AllObjects: +50 (or any action you want)
  1. Explanation:
  • The For each object AllObjects loop goes through every object in the group one by one.
  • Inside the loop, you check if the object’s name matches the variable (SelectedObject).
  • If yes, you move it (or do anything else).
1 Like

Alright, that did the job. Thanks Angrill0n!

1 Like