#1
Posted 18 May 2016 - 06:45 AM
How would I go about this?
I thought maybe I could have both monitors in an array but I don't know if this is possible.
#3
Posted 18 May 2016 - 08:14 AM
Thanks I'll try this
Edited by DTM450, 18 May 2016 - 08:55 AM.
#4
Posted 18 May 2016 - 08:50 AM
Edited by DTM450, 18 May 2016 - 08:50 AM.
#5
Posted 18 May 2016 - 10:55 AM
If you just want to use the in built button function, the easiest way would be to create an array of touchpoint pointers, one for each monitor, and loop through this array and create an array of function pointers that are structured like:
function() return otherFunction(touch[i]) endAnd then use unpack on this array inside a parallel.waitForAny() call.
os.loadAPI("touchpoint") local function runButtons(t) while true do local event = {t:handleEvents()} if event == "button_click" then if t.buttonList[event[2]].func then t.buttonList[event[2]].func() end end end end --#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666" local touch = {} for a,v in ipairs(monSides) do touch[a] = touchpoint.new(v) end --#Define your buttons here. As well as any functions they should run local runTable = {} for a,v in ipairs(touch) do runTable[a] = function() return runButtons(touch[a]) end end parallel.waitForAny(unpack(runTable))Coded it up on a whim because it was an interesting problem, mind you anything you want your buttons to do you have to code, but this 'should' allow for you to set up touchpoints on each monitor, as well as automatically handle buttons and running functions per buttons.
Edited by Dragon53535, 18 May 2016 - 11:00 AM.
#6
Posted 19 May 2016 - 04:19 AM
Dragon53535, on 18 May 2016 - 10:55 AM, said:
yes from both
heres what I have so far but I'm having trouble wrapping my head around it
*snip* --#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666" monSides = {"monitor_0","monitor_1"} local touch = {} for a,v in ipairs(monSides) do touch[a] = touchpoint.new(v) end --#Define your buttons here. As well as any functions they should run local runTable ={add("b1", t:flash(event[2]),1,1,4,1,colours.red,colours.lime) } for a,v in ipairs(touch) do runTable[a] = function() return runButtons(touch[a]) end end parallel.waitForAny(unpack(runTable))
would I be able to populate the monSides table with peripheral.find("monitor")
and I'm not sure where I put the t:draw function and would I still need to use the t = touchpoint.new() declaration to be able to use the 't:'
#7
Posted 19 May 2016 - 04:47 AM
Make monSides a local table.
Nono, you're not going to use t = touchpoint.new at all, that's what the first loop does, it create a new table and puts a touchpoint object (what touchpoint new gives) into that table for each monitor you tell it to. So touch[1] is going to be the touchpoint for "monitor_0"
Don't touch the runTable table. Moreso because you never actually closed it, and because it's going to be filled with funciton pointers.
As for adding buttons, you need to use touch[number]:add to add them. For your t:flash()
function() touch[number]:flash("b1") end
So the entire add for b1 would be.
touch[1]:add("b1",function() touch[1]:flash("b1") end,1,1,4,1,colors.red,colors.llime)
Edited by Dragon53535, 19 May 2016 - 04:48 AM.
#8
Posted 19 May 2016 - 05:50 AM
also changing :flash("b1") to :flash(event[2]) should do the same thing. using event[2] simplifies the code so you don't have to edit multiple parts of the code
revised code
--#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666" local monSides = {"monitor_0","monitor_1"} local touch = {} for a,v in ipairs(monSides) do touch[a] = touchpoint.new(v) end --#Define your buttons here. As well as any functions they should run --#This loop adds and draws buttons to all screens for a,v in ipairs(monSides) do touch[a]:add("b1",function() touch[a]:flash("b1") end,1,1,4,3,colors.red,colors.lime) touch[a]:draw() end local runTable ={} for a,v in ipairs(touch) do runTable[a] = function() return runButtons(touch[a]) end end parallel.waitForAny(unpack(runTable))
Edited by DTM450, 19 May 2016 - 05:53 AM.
#9
Posted 19 May 2016 - 08:32 AM
Revised2:
os.loadAPI("touchpoint") local function runButtons(t) while true do local event = {t:handleEvents()} if event == "button_click" then if t.buttonList[event[2]].func then t.buttonList[event[2]].func(t,event[2]) end end end end --#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666" local monSides = {"monitor_0","monitor_1"} local touch = {} for a,v in ipairs(monSides) do touch[a] = touchpoint.new(v) end --#Define your buttons here. As well as any functions they should run --#This loop adds and draws buttons to all screens for a,v in ipairs(monSides) do touch[a]:add("b1",function(self,param1) self:flash(param1) end,1,1,4,3,colors.red,colors.lime) touch[a]:draw() end local runTable ={} for a,v in ipairs(touch) do runTable[a] = function() return runButtons(touch[a]) end end parallel.waitForAny(unpack(runTable))
Changed the function call to pass the touchpoint table to your button function, as well as the button name. Changed the function declaration of your flash to accept the arguments and use them for flash.
Edited by Dragon53535, 19 May 2016 - 08:33 AM.
#10
Posted 19 May 2016 - 09:57 AM
Edited by DTM450, 20 May 2016 - 12:39 AM.
#11
Posted 20 May 2016 - 12:41 AM
also I'm running CC 1.75 but I dont think that should matter to much
#12
Posted 20 May 2016 - 05:42 AM
On the if statement inside the runButtons function, add [1] after event.
if event[1] == "button_click" then
#13
Posted 20 May 2016 - 05:47 AM
Dragon53535, on 20 May 2016 - 05:42 AM, said:
On the if statement inside the runButtons function, add [1] after event.
if event[1] == "button_click" then
XD okey dokey
*edit*
WOOH its working thanks a ton for your help
Heres the full functioning code in the spoiler for anyone who wants it. Also on pastebin
Edited by DTM450, 20 May 2016 - 05:58 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users