Hello
I have completed walking-astronaut game
Can you tell me how to add “Enter your name” Gui screen for mobile device ?
So user enters his name
I know how to make it display once
But dont know how to implement it (and the transfer between screens)
if you can give sample code is usefull!
Thanks
Hello
Any help please?
Hello @Salmo!
Check out a basic example:
Check out this thread on showing keyboard on mobile:
For more advanced usage check out GUI libraries like Gooey:
Or Druid:
If you will stuck with something specific, let us know
For this I recommend Monarch:
Im doing it with simple collection proxy
I have gameplay.collection which holds all the gamelpay
and opening.collection, which contains 1 game object (welcomegameobject) that has collection proxy to point to gameplay.collecction
the welcomegameobject go, has a gui file welcome.gui that has script file
welcome.gui_script
upon clicking , it should load gaemplay.collection, BUT ITS NOT LOADING IT, ALL I SEE IS BLAcK SCREEn, PLEASE HELP
_G.username = ""
local is_main_loaded = false
function init(self)
-- Acquire input focus for this GUI
msg.post(".", "acquire_input_focus")
-- Initialize message
self.message = ""
-- Show keyboard
gui.show_keyboard(gui.KEYBOARD_TYPE_DEFAULT, false)
-- Get reference to the continue button
self.continuebutton = gui.get_node("continuebutton")
end
function on_input(self, action_id, action)
if action_id == hash("touch") then
-- Check if the touch event is on the continue button
if gui.pick_node(self.continuebutton, action.x, action.y) then
print("Continue button clicked")
-- Get the text from the label node
local label_node = gui.get_node("labelidhere")
_G.username = gui.get_text(label_node)
print("Username set to:", _G.username)
-- Load the gameplay collection if it's not already loaded
if not is_main_loaded then
print("Loading gameplay.collection...")
msg.post("welcomegameobject#main_proxy", "load")
is_main_loaded = true
else
print("Gameplay collection is already loaded.")
end
end
end
-- Handle text input
if action_id == hash("type") then
self.message = self.message .. action.text
local label_node = gui.get_node("labelidhere")
gui.set_text(label_node, self.message)
elseif action_id == hash("backspace") and action.repeated then
local l = string.len(self.message)
self.message = string.sub(self.message, 0, l - 1)
local label_node = gui.get_node("labelidhere")
gui.set_text(label_node, self.message)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
print("Collection loaded:", sender)
-- Disable GUI elements from the current screen
gui.set_enabled(gui.get_node("continuebutton"), false)
gui.set_enabled(gui.get_node("labelidhere"), false)
-- Optionally disable or remove the entire opening collection if necessary
is_main_loaded = true
elseif message_id == hash("proxy_unloaded") then
print("Collection unloaded:", sender)
is_main_loaded = false
end
end
your code goes here
please help me @Pawel
I think you are just forgetting to enable the collection when you receive the “proxy_loaded” message
function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
-- New world is loaded. Init and enable it.
msg.post(sender, "init")
msg.post(sender, "enable")
-- Disable GUI elements from the current screen
gui.set_enabled(gui.get_node("continuebutton"), false)
gui.set_enabled(gui.get_node("labelidhere"), false)
-- Optionally disable or remove the entire opening collection if necessary
is_main_loaded = true
end
end
you can check the manual, they show how you enable the collection once it’s loaded
Also you don’t get any errors in the console?