I should prefix this by saying that while I’ve done game dev before I haven’t used defold until this week :).
So I have a simple teal module:
local M = {}
-- Define the type of the action argument
local record Action
x: number
y: number
end
-- Function to update hover state on a list of GUI nodes
function M.update_hover(items: { string }, action_id: integer | nil, action: Action): boolean
print("update havoer")
if action_id ~= nil then
return false
end
--
for _, item in ipairs(items) do
local node = gui.get_node(item)
if gui.pick_node(node, action.x, action.y) then
local current_color = gui.get_color(node)
local yellow = vmath.vector4(1, 1, 0, 1)
local white = vmath.vector4(1, 1, 1, 1)
if current_color == yellow then
gui.set_color(node, white)
else
gui.set_color(node, yellow)
end
end
end
return true
end
return M
To update some highlights on some buttons. When I run tl gen
from the command line it all works fine and I end up with the corresponding lua file, but when I try to build from inside defold it complains that gui and vmath are unknown variables.
I’ve tried defined the types in a globals.d.tl
and add that in my global_env_def
in tlconfig.lua but get the same issue.
Is this because there’s no types defined in defold for teal?
For reference here’s my globals.d.tl:
-- vmath.vector4 type
global record vmath.vector4
x: number
y: number
z: number
w: number
end
global record vmath
vector4: function(x: number, y: number, z: number, w: number): vmath.vector4
return {x = x, y = y, z = z, w = w}
end
end
-- gui type
global record gui
get_node: function (name: string): string
pick_node: function (node: string, x: number, y: number): boolean
get_color: function (node: string): vmath.vector4
set_color: function(node: string, color: vmath.vector4): nil
end
Any tips/help appreciated.