Coin/gui error? (SOLVED)

Getting this when the frog picks up coins.
WARNING:DLIB: Failed to send announce message (-22)
WARNING:DLIB: Failed to send announce message (-22)
WARNING:DLIB: Failed to send announce message (-22)
WARNING:DLIB: Failed to send announce message (-22)
WARNING:DLIB: Failed to send announce message (-22)
ERROR:SCRIPT: level/controller.script:57: attempt to perform arithmetic on field ‘score’ (a nil value)
stack traceback:
level/controller.script:57: in function <level/controller.script:40>
ERROR:SCRIPT: level/controller.script:57: attempt to perform arithmetic on field ‘score’ (a nil value)
stack traceback:
level/controller.script:57: in function <level/controller.script:40>
ERROR:SCRIPT: level/controller.script:57: attempt to perform arithmetic on field ‘score’ (a nil value)
stack traceback:
level/controller.script:57: in function <level/controller.script:40>Uploading…

1 Like

Can you post a sample of your source code for the involved scripts?

Go.property("speed", 6)

local grid = 460
local platform_heights = { 100, 200, 350 }
local coins = 3 
 local coins = coins
    if math.random() > 0.5 then
        f = "#platform_long_factory"
        coins = coins * 2 -- Twice the number of coins on long platforms
    end
    
function init(self)
    msg.post("ground/controller#script", "set_speed", { speed = self.speed })
    self.gridw = 0
    self.spawns = {} 
end

function update(self, dt)
    self.gridw = self.gridw + self.speed

    if self.gridw >= grid then
        self.gridw = 0

        -- Maybe spawn a platform at random height
        if math.random() > 0.2 then
            local h = platform_heights[math.random(#platform_heights)]
            local f = "#platform_factory"
            if math.random() > 0.5 then
                f = "#platform_long_factory"
            end

            local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
             msg.post(p, "set_speed", { speed = self.speed })
    msg.post(p, "create_coins", { coins = coins })
    table.insert(self.spawns, p)
        end
    end
end

function on_message(self, message_id, message, sender)
    if message_id == hash("reset") then 
        -- Tell the hero to reset.
        msg.post("hero#script", "reset")
        -- Delete all platforms
        for i,p in ipairs(self.spawns) do
            go.delete(p)
        end
        self.spawns = {}
    elseif message_id == hash("delete_spawn") then 
        for i,p in ipairs(self.spawns) do
            if p == message.id then
                table.remove(self.spawns, i)
                go.delete(p)
            end
        end
        
        elseif message_id == hash("score_coin") then
        self.score = self.score + 50
        msg.post("hud", "set_score", { score = self.score })
        
    end
end
1 Like

self.score is never given an initial value, which means it will be nil, and you are trying to add 50 to nil, which obviously won’t work. Do self.score = 0 in your init() function and in the snippet of code that resets the game in on_message().

1 Like

Thanks, but I also tried that way as well and it didnt work for me. I followed from the tutorial that was on the youtuve channel. After doing what you said again I get this error:
ERROR:SCRIPT: level/hud.gui_script:10: attempt to index field ‘set’ (a nil value)
stack traceback:
level/hud.gui_script:10: in function <level/hud.gui_script:7>
ERROR:GAMESYS: Error when dispatching message to gui scene: -2. Message ‘set_score’ sent from main:/level/controller#script to main:/level/hud#.
INFO:SOUND: Waiting for OpenAL device to complete

local text_nodes = {“score”, “score_text”, “life2”, “life3”, “life”, }

function intit(self)
reset_lives(self)
end

function on_message(self, message_id, message, sender)
if message_id == hash(“set_score”) then
local s = gui.get_node(“score”)
gui.set.text(s, message.score)

This is the part of the script that deals with the score and lives, both of which do not want to work for me. I give one thing a value it wants another to have one. Not sure what im doing wrong

The error message specifies that you are trying to access something named set on line 10:

gui.set.text(s, message.score)

The function is called set_text()

1 Like

Thank you, hadnt noticed i typed that, got the gui working perfeftly now!