Posted 18 February 2013 - 03:49 PM
I wish to implement what I think is called an Object Oriented method, where all of the object's properties and what it does is stored in a table entry. The end goal is to create a function that can do any command I need without having to code for every possible command type. In this case, it would be a button that could be triggered by a touchscreen even that executes a command upon being pressed.
My code would be something like the following:
What command or function would allow me to run the command listed in the table button1.onPress?
My code would be something like the following:
--Init variables
GUI = {button1={xMin = 1,xMax = 2, yMin = 1, yMax = 2,onPress="redstone.setBundledOutput("back", colors.white)"}}
--functions
function RangeXY(X, xMin, xMax, Y, yMin, yMax)
if X >= xMin and X <= xMax and Y >= yMin and Y <= yMax then --check if i got the "greater than or equal to" sign right!
return true
else
return false
end
function updateGUI(GUI)
--code goes here to draw button based on table entries in GUI
end
updateGUI(GUI)
--main loop
while true do
event, var1,var2,var3 = os.pullEvent()
if event == "monitor_touch" then --if event was a touchscreen input
monitor, X, Y = var1,var2,var3
for key, table in ipairs(GUI) do
if RangeXY(X, table.xMin, table.xMax, Y, table.yMin, table.yMax) then --this would be true if the player clicked the screen within the button area
dosomethingwith(table.onPress) -- this line will run the command stored as a string in the GUI table. WHAT MUST IT BE?
end
end
updateGUI(GUI)
end
What command or function would allow me to run the command listed in the table button1.onPress?
Edited on 18 February 2013 - 02:59 PM