[SOLVED by workaround] How to put string of object variable into expression

I need to write expression like
Platforms.X() - CameraWidth()
I have object variable called G which is string

What i wanna achieve is
Object.Variable(G).X - CameraWidth()

How to i put there name of object variable and let expression it is name of object?

So in your example, Object.Variabe(G) would equate to the word Platforms? If so, GDevelop doesn’t allow using a string variable to reference an object name directly.

You may be able to get around this though, but it’ll be a tad hacky.
Create an object group of each of the objects you want to reference
Use a repeat event to iterate over each object in the object group
Use a string compare of the object name and the name you want, applying the action you want.

Something like:

1 Like

Thx but that is far from what i need

Maybe i show you what i want to achieve and you can give me a tip on how to do it

So what is in red rectangle on top is where i need the end user to input Group name he created (i am trying to make example out of minimap)
And this is last obstacle i need to overcome one way or another
What is in lower red rectangle is where i did put that variable
In green is where it also need to go
I do not really care how long variable or possible expression will be or what i need to do
As long as on top in red rectangle end user type a group name and that is all he needs to do to reference group he made
Which will be displayed as layer on minimap
Maybe there is other way to shove in there Group name?
I only need a way to shove in there that name or allow player to select it from object list

And then we will have this in our games with ease

2023-12-09_06_12_Tb7JXscvcM_GDevelop

disregard (yes, the post must be 20 characters. Is this better)

As I wrote before, GDevelop cannot reference an object using a variable string. The end user will have to replace the template object name with their own object name.

And I’m not sure if it could even be done with Javascript.

1 Like

Ok, I think I understand. For this to work, the end user would have to use that object group name or the event would need to be in an extension. Even then, you can’t pass an entire group, you’d have to use several parameters. That would give it the desired flexibility.

1 Like

What?

My goal is to 1st make example out of it that work without extensions
Then i wanna make extension out of it
I know how to do it in extension where i can simply add “Object” as reference everywhere

Where in extension end user will only select that object from his list or a object group
I have no problem in shoving in there several parameters
I only need for end user to give as little input as possible

Damn now that i think of it
Maybe solution here is to make extension that will let me reference objects/groups
I could still go with events but use that small extension to gain ability to reference any object or group anywhere in events sheet i want

If any1 one have other idea i am open for suggestions

I think i will end up making extension JUST so i can just reference objects or groups
Literally it only allow you to select object or a group and do nothing
And now you will be able to reference it in events sheet
I still am looking for other way to solve it
So i am open for ideas

@Keith_1357
@MrMen
Or maybe i went wrong way?
Look my idea was to use variable string and put it into expression

But that was only idea i had
Maybe there is another way?
I do not need it to be variable string
I can use any method possible
Where in one place i put object or group name and now i can reference it in expressions and other places

Any ideas?
Well other than going with extension

I can only think of an extension or behavior. Even JavaScript would require an extension to pass the values to. I think the extension is the way to go.

1 Like

That way I posted is the only one I am aware of. If you do find or work out another way, please share it. This kind of question has been posed before, but there’s never been an answer. So if you do work out a way, it’d be greatly welcomed as a solution. And if it is the extension way, then consider making it available through the GDevelop extensions.


This is a quote from a post from last year:

I think my best option right now is to make that extension to reference groups and objects
I think Referencer will be good name
But i’m considering ObjectAndGroupReferencer maybe just ObjectReferencer

Any suggestions or ideas are welcome
I will notify you here when it will be ready

Extensions set up a sort of reference with the parameters. I don’t know how that works internally. The closest thing that I can think of is object linking. If you liked 2 objects at the beginning you could check if there were objects linked to another object. Although with linking you still need a known object to link it to. So, why not just use it?

The other option is a behavior. That would create a sort of automatic link.

No matter what you do, there’s going to be a need for a known object unless all of the actions are self contained like an extension, behavior or prefab object. I really need to utilize prefab objects more but they’re still missing things and take too much setup. I hope they continue to work on prefabs. They’re like a game within a game.

1 Like

I am stupid as brick
I am fully aware of what i can do in gdevelop
Yet i am unable to realize what can be used to solve my problems

CTRL + F in events sheet
And now you have replace tool there
As simple as that OMG

There is no need for me to try making extension for it anymore so my problem is solved
Maybe it will solve also your problem?

2 Likes