i am trying to create a button that plays randoms sound once clicked.
also once the user hears the sound he will click the right object and then gains a point.
can anyone help with this i am new to defold and could use some assistance?
Here’s an example of how to create a button: Button
Here’s how to play a sound: Music
You generate random numbers using math.random(from, to)
. Seed with math.randomseed(os.time())
.
Use the same principle as the buttons for clicking the objects. There’s no need to use game objects for this. Use gui box nodes for the things to click as well.
Keep track of and increase score in the same script:
local function increase_score(self, amount)
self.score = self.score + amount
gui.set_text(gui.get_node("score"), tostring(self.score))
end
function init(self)
self.score = 0
end
function on_input(self, action_id, action)
if right object is clicked then
increase_score(self, 1)
end
end
2 Likes