Long time no see! Because of the recent global events I have some free time to spare and I have an idea for a multiplayer prototype. I’m using Colyseus. I set up everything. It works! I try to send data to my localhost and it receives it… everything is okay. But then I glance to my Defold console and there was an error :
ERROR:SCRIPT: /assets/client.script:25: attempt to index upvalue ‘room’ (a nil value)
stack traceback:
/assets/client.script:25: in function </assets/client.script:23>
I’m sending a plain string ( room:send("word"))… and I don’t think a string is a nil value. I’m still new to Lua!
Yeah, I can provide you with anything you need. I mean the code works but it bugs me out every time i get the error. I’ve just attached this simple example I found on the “Getting started” section of the Colyseus docs to a Game Object in the main collection. I’m just in the beginning of the prototype and I don’t have much except a Platypus driven sprite.
Here is my code:
local ColyseusClient = require "colyseus.client"
local client
local room
function init(self)
client = ColyseusClient.new("ws://localhost:2567")
client:join_or_create("chat", {}, function(err, _room)
if err then
print("JOIN ERROR: " .. err)
return
end
room = _room
end)
end
function update(self, dt)
client:loop()
room:send("word")
end
Yes, that is definitely it. The room will not be created on the first frame and the update() function will obviously be called immediately from application start. Checking that room is not nil is the correct solution to avoid the problem.