How can I make a score display and update every frame? (SOLVED)

I have a juggling game in which you have to bounce a ball on a paddle and the score goes up, but I am new to Defold and need help in making the script work.

It depends on what you wish to achieve :smiley: But if you are new, the best option is to at first follow a tutorial and then modifying it to suit your needs :wink:

Related topics (proving also itā€™s really not that hard to search the matter, because almost the same question was asked in the topic below, so itā€™s always better to try to find anything, unless you have a specific question that we will happily try to answer :wink: ):

3 Likes

Thank you very much for the quick response, I will try out these tutorials and see which one suits best for me!

I hope, this will help you to start with :wink:
If you will stumble upon anything problematic, let us know :wink:

Thank you very much! The community here is very helpful and polite!

P.S. Notice the video linked above is the 3/3 part in the turorial series, while the whole 3-part tutorial is just around hour or so, so I think itā€™s worth doing it whole :wink: (also I made it, so if you have any feedback on it, let me know :smiley: )

1 Like

Alright, I will!

1 Like

I have a question, when I send the message an error called ERROR:GAMEOBJECT: Instance ā€˜unknown:7522881751777254728ā€™ could not be found when dispatching message ā€˜helloā€™ sent from main:/Paddle#Paddle_Movement shows up

Is it because I havenā€™t specified the instance in the script yet?

How you send the message? Where is your game objects where you want to send your message to?

It might be just wrong addressing.

For easiest addressing:

print("My url: ", msg.url())

in init() in the script, to which you want to send your message.

This is the easiest way to get to know the correct absolute address of this script (so recipientā€™s addrress) :wink:

That way, you can use it to write correct address in msg.post(), but please, read more about addressing:

Or if you prefer videos, I have another one for you! :smiley:

I also have a library called Pigeon, that simplifies sending messages - in each recipient you must though subscribe to given message, but instead you donā€™t care about addressing - Pigeon just sends the message to subscribers :wink: (yep, thereā€™s also a video about Pigeon on my channel, but enough of shameless plugs I think, google it ;D )

Is it ok if I send you the scripts?

This is my movement script, along with the msg.post score thing
local score = ā€œgui#Scoreā€
local speed = 250
function init(self)
msg.post(".", ā€œacquire_input_focusā€)
self.dir = vmath.vector3()
end

function final(self)

end

function update(self, dt)
if vmath.length_sqr(self.dir) > 1 then
self.dir = vmath.normalize(self.dir)
end
local p = go.get_position()
go.set_position(p + self.dir * speed * dt)
self.dir = vmath.vector3()
end

function fixed_update(self, dt)

end

function on_message(self, message_id, message, sender)

end

function on_input(self, action_id, action)
if action_id == hash(ā€œrightā€) then
self.dir.x = 1
msg.post(ā€œScore#mainā€, ā€œhelloā€)
elseif action_id == hash(ā€œleftā€) then
self.dir.x = -1
end
end

function on_reload(self)

end

I donā€™t have an enemy or score upper thing yet, so I just used on_input to send the message.

You have to have then a script ā€œmainā€ inside ā€œScoreā€ game object in the very same collection
( the same from which you have your object with script that sends this message :wink: )

I will try it thank you!

How can I add the gui script into the game object the option does not appear when I want to add a component file?

Iā€™m so sorry if Iā€™m being dumb right now, itā€™s just that Iā€™m new at defold, completing only the movement tutorial.


This is what shows up when I want to add the gui script into the game object

You have a great channel, that Godot vs. Defold video blew up, congratulations!

You should add the gui script to the gui component.