This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sniper_killshot's profile picture

:65: ')' expected error

Started by Sniper_killshot, 07 April 2020 - 04:01 AM
Sniper_killshot #1
Posted 07 April 2020 - 06:01 AM
hi all,

Im trying to make a touchscreen monitor control program for an atomic science reactor, not using any API. Ive found a framework, and greatly expanded on it. however, ive run into an issue where clicking anywhere on the monitor turns off a previously on button. i believe i have narrowed this down to this particular framework not having x and y end values for the buttons. i try to add them and i get a ')' expected error, however i can't find any misplaced or missing parentheses.

if anyone could help, or indeed, make any suggestions, that would be great.

SK


Pastebin link

http://prntscr.com/ruhami

line 26
http://prntscr.com/ruhax3
Edited on 07 April 2020 - 04:04 AM
magiczocker #2
Posted 07 April 2020 - 03:43 PM
In the lines 65 and 66 you forgot a comma between the 10 and the text.
Sniper_killshot #3
Posted 08 April 2020 - 03:14 AM
In the lines 65 and 66 you forgot a comma between the 10 and the text.

fixed that, and the errors gone away, but now the buttons dont work.

new pastebin link: https://www.pastebin.com/ZG4ZdEur

sk
Lupus590 #4
Posted 08 April 2020 - 01:37 PM
Why do you not want to use other peoples APIs? I would recomend using touchpoint. If you are on newer CC with require support then you might want to use the version that I've ported to require.
Edited on 08 April 2020 - 11:44 AM
Lupus590 #5
Posted 08 April 2020 - 01:50 PM
You should test for the boundry of your button seperatly from it's state.
magiczocker #6
Posted 08 April 2020 - 07:07 PM
I modified your code a little bit. If you have questions, feel free to ask :)/> .

local mon = peripheral.wrap("left")
local buttons = {}
local function create_button(start_x,start_y,text,rs_side)
    local button = {}
    local text = text or ""
    local active
    local start_x = start_x
    local start_y = start_y
    local rs_side = rs_side
    button.toggle = function()
	    active = not active
	    rs.setOutput(rs_side, active)
    end
    button.draw = function()
	    mon.setCursorPos(start_x,start_y)
	    mon.setBackgroundColor(active and colors.lime or 16384)
	    mon.write(text)
    end
    button.get_pos = function()
	    return start_x, start_y, start_x + #text - 1
    end
    button.set_text = function(txt)
	    text = txt
    end
    return button
end
-- clear monitor
mon.setBackgroundColor(32768)
mon.clear()
-- create buttons
buttons[#buttons+1] = create_button(5, 10, " Hello there ", "top")
buttons[#buttons+1] = create_button(20, 10, " General Kenobi ", "right")
-- draw buttons
for i=1,#buttons do
    buttons[i].draw()
end
-- click event
while true do
    local event,_,x,y = os.pullEvent()
    if event == "monitor_touch" then
	    for i = 1, #buttons do
		    local tmp = {buttons[i].get_pos()}
		    if x>=tmp[1] and x<=tmp[3] and y == tmp[2] then
			    buttons[i].toggle()
			    buttons[i].draw()
			    break
		    end
	    end
    end
end
Edited on 09 April 2020 - 05:51 AM
Lupus590 #7
Posted 08 April 2020 - 07:45 PM
[.code][./code] to do code tags or click on the <> icon
magiczocker #8
Posted 08 April 2020 - 08:41 PM
[.code][./code] to do code tags or click on the <> icon

Thank you for your advice.