Till Example.ObjectName() only works if the object is inside the scene as an instance

Any reason why?

Been messing up with my game’s storage cause I want to add a different market where you can buy characters with money.

Normally, I save each character in a storage group that is made by their name. Say, for example, my object name is Hero001.

When Gdevelop asks me for the text I write Hero001.ObjectName(). instead of “Hero001”

When I do, in this scene, my characters are already inside the scene as instances and Gdevelpo takes their name and saves them without issue.

However, if the Objects are not inside the scene as instances, if I try to get the object’s name, Gdevelop won’t give me anything in return.

Is this a bug, or is this supposed to work like this? How can I get the object’s name if the object isn’t inside the scene as an instance? Without typing it in the usual way.

I am not sure i understand your issue
But in case i do

What you are trying to do is read value of something that does not exist
In this case name

You will think something like come on its a name of object its in editor
And you are right but its not on scene

Think of it as gdevelop need to pick your object from scene to read its value
NOT from editor itself

Like you want to fire bullet from player
Ok so can you have your player in editor on object list and not in scene to fire bullet from player?

Imagine this
Tell me how much money i have in my wallet right now?
Can you?
You know i have wallet i mean i can send you screenshot of it proving i have
Even if i have 100$ or 0$ can you tell me exact amount?
Like just because you know i have something does not mean you can use that information to set some value

Now another example
You want to set HP bar width to player HP
So imagine enemies shoot your player he loses HP and bar shrinks
Perfectly logical
Now what if you kill player by player touching spikes
Or getting in range of bomb explosion
Like instant kill
If you just deleted player
HP bar will stay at whatever value HP was of player (assuming its object var Player.HP)
CAUSE even so player don’t exist anymore so there is no HP variable anymore and there should be no value to read from
That is exact issue here there is nowhere to read value from now
So bar stayed at last width equivalent to HP variable value
A proper way in this case to kill your player would be to either subtract max HP from player or set it to 0
And now HP bar would shrink properly

JUST having your object in object list does not equal to having it on scene
Whole magic comes from the fact your object is on scene and engine can pick such object to read values from it
Same goes for names

Only exception is creating objects from group
Where is still kinda not exact same thing
When you create object from group and you don’t want to constantly create 1st object
You have action to specify text with name of such object instead of manually selecting it from list of your objects

So you are not like managing objects from list
But instead of being forced to manually select them you are given chance to shove in there text as placeholder for what you should normally do manually

1 Like

Oh okay, cool, I see now.

Thank you for the explanation.

It confuses me a bit cause I was under the idea that since Gdevelop can create objects from the objects list without them existing on the scene, that it wouldn’t have a problem just reading the object’s name. I mean, it has to read from somewhere the name to create the object, right?

I’ll just type the name manually then :stuck_out_tongue:

1 Like