I’ve never understood how to use the colon operator, but I want to start using it. Edit: I know i have to make a table to hold the methods now, oops. I thought the colon meant that self was passed in from the variable (see m=map()) but ahh I’m not quite understanding what I’m doing.
I want it to be so i can call m=map(), then map.coords = {vec2(x,y)} and so on like m=mesh() but I’m confused on how that is even done in the first place. Umm, thats basically the same as if i did map:init, isn’t it? I just want to remove the init method part.
But i noticed if i print(mesh()), it will actually say mesh: (0xwhatever, length=0), whereas with a table it just goes table:whatever (is thats the id?) so I am curious how I can get my own functions to print like that, if it is possible. I really should have waited a few hours before posting this, i haven’t given up yet and just end up editing it. Sorry id delete it, if i could figure out how.
-- original post code
function map()
local t = {coords={},
tints={},
radiuses={}}
return t
end
function map:coord( i, x, y, z )
if x and y and z then
self.coords[i] = vec3(x,y,z)
else
return self.coords[i]
end
end
function setup()
m=map()
m.coords = {vec3(100,100,1), vec3(200,100,1), vec3(50,50,1)}
print( m:coord(1) )
end
Here is the second post code. I haven’t made much progress, since the method still gives an error I’m not sure what I’m doing wrong
map = {}
function map:init()
local t = {coords={},
tints={},
radiuses={}}
return t
end
function map:coord( i, x, y, z )
if x and y and z then
self.coords[i] = vec3(x,y,z)
else
return self.coords[i]
end
end
function setup()
m=map:init()
m.coords = {vec3(100,100,1), vec3(200,100,1), vec3(50,50,1)}
print(m.coords[1])
print( m:coord(1) )
end