[SOLVED] Target specific instance from a text element

I have two instances of an object “Car”. I use a text to display the variable “Angle” of the first instance with ToString(Car.Variable(Angle)).

I want to display also the variable “Speed” of the second instance of “Car”.


  • I gave each instance of “Car” its unique “Id” variable, but I don’t know how to tell the text to target Car-with-Id=2.
  • I know how to use a “for each” loop, but I don’t want to display the same set of variables for each instance.

Hi, if I understood well what you need, you just need one for each loop, and inside 2 condition->action.

For each car object :

  • if object variable Id =1, then display angle
  • if object variable Id =2, then display speed

Means the loop will take a look at every car Objet, but won’t display the same thing for each.

Thank you, this works for me.

However I’m still wondering if there’s a more direct way to target Car-with-Id=2.
Something like “write a text with angle-of-car1 and speed-of-car2”.
If so I want this tool in my belt.

(I’m very new and I’m trying to learn the best solution available, so I won’t find myself having to re-learn in the future)

1 Like

Firstly, for global, scene, or object variables, you can never access them directly according to the value they have. Only by their name. You can acces directly variable(perso. 1.name), but cannot access the variable perso.n whom name is Robert. The only way is to loop, to check variables and look among them which one is egual to Robert.

For instances you cannot access them by their name. You can do an action for all instances of a same object or all instances of same object group. Also if there is only one instance of an object, you don’t need the loop to select it.

So to select instances you can use object groups, object, or loops “for each” to look for specific instances. In your case, if you had 2 different objects car1 and car2, you could directly ask the code to give you car1.speed and car2.angle. Since you have one object, you need the loop to select the instance.

Another thing: you cannot for actions access dynamically an object, which means the name of the object that will do the action has to be fully defined in the event. It’s not a string, so you cannot say for example “move car[variablestring(n)]”.
This sometimes annoys me.

1 Like

Super clear and insightful. Thank you very much.

1 Like