It seems something simple, but I would like to get in text the name of the gameobject. At the moment I use go.get_id() but in the console looks like this.
DEBUG:SCRIPT: Touch! item[/my_name_item_1]
It seems something simple, but I would like to get in text the name of the gameobject. At the moment I use go.get_id() but in the console looks like this.
DEBUG:SCRIPT: Touch! item[/my_name_item_1]
A game object does not have a name. It has an id, which is a number (hash of the string id you write in the editor). In debug mode we do an extra lookup of the hash to be able to print the original text representation of the id.
What do you need the “name” for? You can do comparisons like this:
if go.get_id() == hash("/my_name_item1") then
print("foo")
end
just remember that this comparison is not true if the object was created by collectionfactory.
In that case go.get_id() == hash(’/collectionX/my_name_item1").
I guess it’s something like Game Object’s “name” field in Unity, right?
I tend to give names to objects (like NPCs) as well, but I do it as a go/script property - a hashed string - example here: Script component properties
As long as you don’t need to display any text to users, strings are not dev-friendly stuff, so you should get used to numbers and hashes (which are also numbers, but made out of “strings”)
Yes I would like to have the gameobject.name field like Unity, and a toggle button for the active and inactive item in the shelf like Unity I think it’s useful, or maybe I’m just used to that. But I think need to make costume shelf with that properties names
You need to remember that not all game engines are the same. Something that works in Unity might not work in Defold and vice versa.
You haven’t really told us what you want to create. Could you please explain what you are trying to implement in Defold?
Hi britzl, at the moment I try to make a drag and drop game, I’m working in a feature when the drag begins in the Gui display the name with this message “you grab this item my_game_object”, but looks like “you grab this item [/my_game_object]” that’s it, I think add a field with the name solve the problem It’s not big deal, but I think was a function like go.name()