Create a tween with a variable instead of an Object name

Hello!

How do I create a tween using a string variable that contains the name of the object as opposed to using the Object’s name in the tween effect?

Here’s the setup:
I have several random objects being created in the beginning of the game. I am using “Create objects by name” and using a random number to pick each object from inside a group. The game is creating these objects and storing each of their names as a string in a respective variable.

Now, when I want to reference a specific object, I can use the variable in various places, but I haven’t found a way to use it in a tween.

I have tried creating an Array and tried to use the index of the variable, I have tried referencing the variable using GlobalVariable(), ToString(), ArrayTools, etc but the tween effect will only accept the Object name, which I don’t have.

How would I tween an object of which I don’t know the name?

Is there something else I could try?

Hi casiokid, I’ve used the extension Extended variables support for referencing objects by a variable name. I haven’t checked whether it works for tweens but it’s worth a look.

Hmmmm I just tried it and no, there is no way of using an expression in the object name field. Good question though, perhaps there’s a different way of looking at it. I’ll put my thinking hat on.

Or, you could try writing your own tween behaviour.

Did you try using a group. If the object’s are already in a group then use the group name with the tween. Just use a condition to pick the object using the variable and something like an object variable or animation. The object variable could be the object name or an ID.

1 Like

Thanks for this! I didn’t try setting a condition defining the specific object within the group I’m trying to tween. I’ll have to add some new object variables and give this a try!

Thanks Bubble!!! Even if that doesn’t work, I wasn’t aware of the “Extended variables support” extension. That could be very useful!

Yes, I could write my own tween behavior. Haven’t gotten there yet! I was hoping for an easier solution. LOL

1 Like