I am seeing some unusual behavior that I just don’t understand. This may not be the best way to do this in the first place, I am just experimenting to learn.
Here is my collection layout:
In station.script I have:
local aide = require "game.aide"
go.property("glow_color", vmath.vector4(0, 0, 1, 0.8))
local THRUST = "thrust"
local THRUST_SPRITE = "thrust#sprite-thrust"
local THRUST_SPRITE_GLOW = "thrust#sprite-thrust-glow"
function init(self)
if go.get_parent() then msg.post(go.get_parent(), aide.MOVING_LISTENER) end
self.move_input = { x = 0.0, y = 0.0 }
-- go.animate("#sprite-center-glow", "tint", go.PLAYBACK_LOOP_PINGPONG, vmath.vector4(0,0,1,1), go.EASING_INOUTBOUNCE, 2)
go.set("#sprite-center-glow", "tint", self.glow_color)
go.set("#sprite-engine-glow", "tint", self.glow_color)
go.set(THRUST_SPRITE, "tint", aide.HIDE)
go.set(THRUST_SPRITE_GLOW, "tint", aide.HIDE)
end
function update(self, dt)
if (self.move_input and (self.move_input.x ~= 0 or self.move_input.y ~= 0)) then
local rot = math.atan2(self.move_input.x, -1 * self.move_input.y)
local angle = 0.0
if rot then angle = rot end
go.set(THRUST_SPRITE, "tint", aide.SHOW)
go.set(THRUST_SPRITE_GLOW, "tint", self.glow_color)
go.set(THRUST, "rotation", vmath.quat_rotation_z(angle))
else
go.set(THRUST_SPRITE, "tint", aide.HIDE)
go.set(THRUST_SPRITE_GLOW, "tint", aide.HIDE)
end
end
function on_message(self, message_id, message, sender)
if (message_id == aide.MOVING) then
self.move_input = message.move_input
end
end
It seems to work just fine when I build the game. I am basically passing whether player is moving through a message to the station script from player script. And in update I am showing/hiding a thrust animation depending on whether or not player is moving. It all works just fine in the game…
However, in my console it is spamming this:
ERROR:SCRIPT: game/player/station/station.script:31: could not find any instance with id '<unknown>'.
stack traceback:
[C]:-1: in function set
game/player/station/station.script:31: in function <game/player/station/station.script:21>
If I comment out 31/32 in station script (the lines that hide the thrust sprites), the error goes away but then the thrust is always visible now (because it is no longer being hidden obviously.) When those 2 lines are there, it disappears, as expected, when not moving but spams that error.
Line 17 on init (same statement, hiding the thrust) also has the same script error, yet works fine.
I must be missing something Defoldy here… but I just can’t seem to figure out what it is. If anyone can spot my problem, that’d be awesome. Feel free to suggest a more Defoldy way to do such a thing too. I’m just at a loss.