project/main/entername.script
2025-08-25 01:59:20 +01:00

66 lines
2.1 KiB
Text

function init(self)
msg.post(".", "acquire_input_focus")
go.set_position(vmath.vector3(527.5,348,0), "background")
msg.post("/entername_gui#entername1", "enterthename", { enter = "enter your initials:" })
self.name = ""
msg.post("/entername_gui#entername1", "written_name", { name = self.name })
self.max_char = 3
end
function final(self)
-- Add finalization code here
-- Learn more: https://defold.com/manuals/script/
-- Remove this function if not needed
end
function update(self, dt)
end
function fixed_update(self, dt)
-- This function is called if 'Fixed Update Frequency' is enabled in the Engine section of game.project
-- Can be coupled with fixed updates of the physics simulation if 'Use Fixed Timestep' is enabled in
-- Physics section of game.project
-- Add update code here
-- Learn more: https://defold.com/manuals/script/
-- Remove this function if not needed
end
function on_message(self, message_id, message, sender)
-- if message_id == hash("type") then
-- self.name = self.name + message.text
-- end
-- msg.post("/entername_gui#entername1", "written_name", self.name)
end
function on_input(self, action_id, action)
if action_id == hash("type") then
if self.max_char > 0 then
self.name = self.name .. action.text
msg.post("/entername_gui#entername1", "written_name", { name = self.name })
self.max_char = self.max_char - 1
elseif self.max_char == 0 then
print("no more characters!!!!!")
end
elseif action_id == hash("backspace") and action.repeated then
self.name = string.sub(self.name, 0, string.len(self.name)-1)
msg.post("/entername_gui#entername1", "written_name", { name = self.name })
self.max_char = self.max_char + 1
if self.max_char > 3 then
self.max_char = 3
end
end
if action_id == hash("enter") then
msg.post("main:/controller#main", "save_name", { name = self.name })
end
if action_id == hash("escape") and action.pressed then
msg.post("main:/controller#main", "escape")
end
end
function on_reload(self)
-- Add reload-handling code here
-- Learn more: https://defold.com/manuals/hot-reload/
-- Remove this function if not needed
end