Here's where clicking is handled (in a for loop), and sorry for my cruddy coding and OOP.
... for k,v in ipairs(self.Scene.View) do ...
Thanks in advance.
Posted 12 November 2017 - 01:48 PM
... for k,v in ipairs(self.Scene.View) do ...
Posted 12 November 2017 - 02:03 PM
Posted 12 November 2017 - 02:32 PM
KingofGamesYami, on 12 November 2017 - 02:03 PM, said:
KingofGamesYami, on 12 November 2017 - 02:03 PM, said:
Posted 12 November 2017 - 02:34 PM
Haddock, on 12 November 2017 - 02:32 PM, said:
Posted 12 November 2017 - 03:06 PM
SquidDev, on 12 November 2017 - 02:34 PM, said:
elseif e[1] == "mouse_click" then
--find what it clicked on
local x = e[3]
local y = e[4]
local button = e[2]
for id,t in pairs(self.Scene.View) do
if t.X <= x and t.Width + t.X >= x then --x matches
if t.Y <= y and (t.Height or 1) + t.Y >= y then --y matches, this is the right object
if t["OnClick"] ~= nil and type(t["OnClick"]) == "function" then
t:OnClick(x,y,button)
end
break
end
end
end
I look through all the objects in the scene using pairs, see if the X and Y matches up (and they do, but not in ipairs with 2 or pairs with 3), then call the OnClick function.local me = QuickDraw.Init() --initing stuff
QuickDraw.AddObject(button) --defined earlier
me.Scene.BG = colors.black
me.Scene:Add("button", "b1")
me.Scene:Add("button", "b2")
--defining properties and stuff
...but if I through in another button, (me.Scene:Add("button","b3")), then pairs doesn't work and I have to switch to ipairs.Posted 12 November 2017 - 03:25 PM
Posted 12 November 2017 - 03:38 PM
Exerro, on 12 November 2017 - 03:25 PM, said:
Posted 12 November 2017 - 03:47 PM
Posted 12 November 2017 - 04:36 PM
Exerro, on 12 November 2017 - 03:47 PM, said:
local a = {
[1]="Hello ",
[3]="World"
}
orlocal a = {}
a.test = "Hi"
0 members, 1 guests, 0 anonymous users