ERROR:GAMESYS: Error when dispatching message to gui scene (SOLVED)

I’m trying to make a score counter that adds 100 points to my score on the GUI when an enemy is shot but I get an error.



d4

Hi and welcome to Defold.

A few things going on here. First of all, you are using the same variable to store two things: A node and a number. Suggest doing something like:

self.score = 0
self.score_node = gui.get_node("score")

The function gui.set_text() takes a node and a text. So in this case it would be:

gui.set_text(self.score_node, self.score)

I also note that you are trying to call tostring(). to.string() is not a valid function, it should be:

tostring(self.score)

However - you do not need to convert the number to a string. You can just pass the number.

2 Likes

In the future, please post code as text.

Use ``` on either side of the code to format nicely.

```
local foo = “bar”
```

Becomes:

local foo = "bar"

This is much more readable and means the code is searchable too!

2 Likes

I just got it to work, thank you very much. :smiley:

1 Like

okay, didn’t know about. Will do

1 Like