Problems with text node functions (SOLVED)

Hi,
I tried to make a editable text field, so I put a text node in a GUI (I need the GUI) and make a text_trigger text_input, and every on_input it checks the text input. This is right, but the code need to append the text, and normally (I have various acknowledgments with Java swing) I tried to get the text node with node = gui.get_node("input"), this is right so, but I don’t know the method to get the current text of the node.
I also tried things like node.get_text(), but it return an error saying that the method don’t exists, and I need to put gui.get_get_text(<node>) (yes, two get_ in the method), when I put it says that the method not exists, and finally I removed one get_ to stay like gui.get_text(node), and not work too.
My code now is like:

if(action_id == hash("text_input")) then
    	local node = gui.get_node("input1");
    	gui.set_text(node, action.text)
end

But my first try is like:

if(action_id == hash("text_input")) then
    	local node = gui.get_node("input1");
    	gui.set_text(node, node.get_text() + action.text)
end

After all this, I thought that was because the concatenation, some programming languages use two dots .. but Java uses a plus cross +, and I am very confused because this.

Now testing if other things like some places of the map works, I note that I can’t put accents in my text (I am from Brazil and my game is for an institution, the accent is in work mãos, the same as hands). I started read something in Defold Device Input page about marked text, but I can’t extract nothing from it.

You can find all the gui methods here: https://www.defold.com/ref/gui/, gui.get_text(node) is correct.

I’m not sure why you’re talking about Java? Defold uses Lua, and Lua uses the two dots for concatenation. There is a good overview of Lua here, with a link to the official Lua manual.

I started talking about Java because I am at an high advanced level in it, but it is too much expensive in making a game simple like the one I need to do, but Lua is very different of all what I know (principally because functions and class names has an underline as separator, not an upper case).

This is by no means a requirement. We have decided to name our API functions using snake_case (gui.get_text) while the Lua APIs themselves use all lowercase (debug.getinfo). Other Lua libraries might use CamelCase. You are free to name your variables whichever way you wish.

Nice! Brazil is the home of Lua. Which institution are you making a game for?

As a rule of thumb all Defold APIs operate on data. The data itself has no functions. A gui node is a user data object without any functions. local text = gui.get_text(node) is the correct way to get text from a node.[quote=“Taarak, post:1, topic:9506”]
I tried to make a editable text field
[/quote]

Did you see this library for making quick GUI mockups?

Hi, @britzl, my game is for “Ministério da Cultura”, that means culture ministry, is for an competition of programming, the prize is high (here in Brazil) but the time to make is low. And I never seen the GUI library that you say, but I have another problem: I am in another institution (the NAAH/S) but Defold Editor 1, it says “This page can’t be show, check if the address is typed correctly”, and then I check that the port in the address is 9998, but in another thread someone says that the port is 8001, but the address is automatically changed again. In Editor 2 the problem is different, I can login but can’t load projects from dashboard, after a while waiting, it says “Cannot open git-upload-pack”.

Here some screenshots (first in Portuguese, sorry):

And here from the Editor 2:

Are you behind a firewall?

I thought it too, I accessed the firewall configurations, first that Defold not is in enter or exit configs, and firewall is not activated.

I’m sure there’s something on the network that is blocking your requests. My recommendation is to use Editor 2 and open a project from disk, ignoring the dashboard for now (since you say that you do not have much time).

All you need is an empty folder with an empty game.project file to get going. Or start from one of our sample projects on GitHub. I have a bunch of examples and games that you can play around with as well.

I can’t load the project from the disk because is in other computer, I have searched to try a way to download projects from Defold’s forums, but I can’t find.

Can you give an example of project you’re unable to load? For projects hosted on GitHub there’s always a Download as Zip link that will download the entire project as a zip file. Unzip it and select game.project when you use Open from Disk.

1 Like

GitHub? I don’t use github to store this type of project, only the Defold itself, I simply synchronize the project. But… Defold stores projects in GitHub? I use git for various purposes, but I never know that Defold automatically stores projects in github (if it stores, I don’t know, as I said).
But now that I’m home (NAAH/S is only for 4 hours) I loaded the project in Defold Editor, and gui.get_text(node) continues to not work, even storing the value into an local variable, it says attempt to perform arithmetic on local 'text' (a string value).

You need to get the node first, then perform operations on the node with the gui.* functions. Like:

local node = gui.get_node("text")
local text = gui.get_text(node)
print(text)

I’m too dumb; @sicher my code is very like your, but I not put the print instruction. After doing this, I note that the problem is not in the gui.get_text(node), but is in the fucking concatenation. I am accustomed with Java, that the arithmetic and concatenation are the same +, but after a 5 seconds search on web I find that concatenation in Lua is two dots .., not a plus cross.
The main problem is solved!

If you create a project from the Defold Dashboard it will be created as a Git project hosted on our servers. You can however chose to host the project somewhere else, for example GitHub. If you use Editor 2 you can host the project anywhere and open it from any location on disk. If you use editor 1 and want to use alternative project hosting please check this forum post.

Ah, yes that is easy to get wrong. Good you sorted it out!

Great! Thanks to solving all my problems in this thread! The post of sven to store projects in Git will help too much.

1 Like