Is it possible to incorporate Variable values to Object names?

For instance, I am creating a game with 100 levels, and each should have a button to access them. I am locking them so that they will unlock as they progress. like this

If [GlobalVariable] <= 0, Create [padlock] on [ObjectName].CenterX(), [ObjectName].CenterY()

I have level buttons 1 to 100, in which their Object Name is lev{number}
I have singlelevelbuttons group containing lev1 to 9 buttons
I have doublelevelbuttons group containing lev10 to lev 99 buttons
the lev100 button stands alone
The Global variable is a structure containing children title 01 to 09, 10 to 99, 100
So GlobalVariable = Levels.0[ToNumber(singlelevelbuttons.LabelText())] and
So GlobalVariable = Levels.[ToNumber(doublelevelbuttons.LabelText())]

So I want to do this:
Repeat each instance for singlelevelbuttons
If Levels.0[ToNumber(singlelevelbuttons.LabelText())] <= 0, Create [padlock] on lev[ToNumber(StrAt(singlelevelbuttons.ObjectName(), 3))].CenterX(), lev[ToNumber(StrAt(singlelevelbuttons.ObjectName(), 3))].CenterY() for singlelevelbuttons

Repeat each instance for doublelevelbuttons
If Levels.[ToNumber(singlelevelbuttons.LabelText())] <= 0, Create [padlock] on lev[ToNumber(StrAt(doublelevelbuttons.ObjectName(), 3) + [StrAt(doublelevelbuttons.ObjectName(), 4))].CenterX(), lev[ToNumber(StrAt(doublelevelbuttons.ObjectName(), 3) + [StrAt(doublelevelbuttons.ObjectName(), 4))].CenterY() for doublelevelbuttons

Is this possible?


If I understood your question correctly, there are couple of solutions.

First, check the action called “Create an object from its name”. You must create an object group and add objects, which you would like to create from its name. Then with the action “Create an object from its name” first you define the group and then the object name as string.

Could you also create only one button to the object list, and add the level information as object variable? Here is the simple example, where I have the Button object having object variable “Level”. Scene variable “LevelButtonsToCreate” holds the information how many buttons are created, and scene variable LevelButtonNow is just a counter.

Hopefully you find this helpful. :slight_smile:

1 Like

Instead of using [expresson].CenterX() and [expression].CenterY(), you store the position of every object in variables, and just do [expressionX] and [expressionY] instead.

Thanks a lot, Its helpful