Chat ability?

Hello again,

I was wondering if any one had achieved a chat system in Defold and how they did it? Currently I’ve been mulling over experiments to try, and my idea was that when the player hit enter, an object named chatbox would achieve focus and activate a “caret” object which would display that the chatbox was awaiting instruction, and a function which waited for any input from the keyboard. It would then display the pressed keys. When the player hit enter a second time, the text (Which would be set as a variable) would be sent as a message to a script which would create a “chat” object with a text child, and set it’s text to the variable. The variable would be reset after the message was sent. Then, somehow, I’d have to recall each object and “bump” it every time a new message appeared to create space for the new one. Does this sound logical and applicable, or would I be forced to do it some other way. Also, is there an easier/simpler way?

Defold’s text triggers make typed input very easy. I never did a chat system but this little snippet is all it took to get basic typing and backspace in one of my projects:

function on_input(self, action_id, action)
	if action_id == hash("text") then
		mytext = mytext .. action.text
		gui.set_text(textnode, mytext)

	elseif action_id == hash("backspace") then
		if action.pressed or action.repeated then
			mytext = string.sub(mytext, 1, -2)
			gui.set_text(textnode, mytext)
		end
	end
end

Britzl posted step-by-step instructions on how to set up something like this here: How to get text input from the user? (SOLVED)

The rest of your design idea sounds sensible to me. I’m sure others who have more experience with this stuff will chime in.

5 Likes

Your question doesnt really cover much about the “sending part”, but if interested I will try to set up a stream in the near future where I will build a multiplayer network engine in Defold (for our own future games). This would include basic networking (as well as quite advanced), including chat using udp in a reliable ordered protocol.

8 Likes

Andreas that would be amazing!!!

1 Like

Yes, I was trying to lay it out as simply as possible, but I realize there would be a lot of messaging involved between the different stages. Absolutely! There would be so much information to gain from that, and I’d appreciate it greatly.

Edit: Now that I reread your message, you were saying “sending” in relation to sending over an internet/lan connection weren’t you? I’m planning on using a single-player chat, essentially writing out the story through the chat box, because most of it will be communications through a computer and will require Y/N (and etc) responses at times. Although, learning how to build a multiplayer network engine would be significantly useful in the future if I ended up coming up with a multiplayer project.

1 Like