Jump to content




:65: ')' expected error


7 replies to this topic

#1 Sniper_killshot

  • Members
  • 12 posts
  • LocationThe Internet Hub, Oslo, Norway

Posted 07 April 2020 - 05: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 by Sniper_killshot, 07 April 2020 - 05:04 AM.


#2 magiczocker

  • Members
  • 46 posts

Posted 07 April 2020 - 02:43 PM

In the lines 65 and 66 you forgot a comma between the 10 and the text.

#3 Sniper_killshot

  • Members
  • 12 posts
  • LocationThe Internet Hub, Oslo, Norway

Posted 08 April 2020 - 02:14 AM

View Postmagiczocker, on 07 April 2020 - 02:43 PM, said:

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

#4 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 08 April 2020 - 12: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 by Lupus590, 08 April 2020 - 12:44 PM.


#5 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 08 April 2020 - 12:50 PM

You should test for the boundry of your button seperatly from it's state.

#6 magiczocker

  • Members
  • 46 posts

Posted 08 April 2020 - 06: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 by magiczocker, 09 April 2020 - 06:51 AM.


#7 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 08 April 2020 - 06:45 PM

[.code][./code] to do code tags or click on the <> icon

#8 magiczocker

  • Members
  • 46 posts

Posted 08 April 2020 - 07:41 PM

View PostLupus590, on 08 April 2020 - 06:45 PM, said:

[.code][./code] to do code tags or click on the <> icon

Thank you for your advice.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users