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

Help me please.

Started by IsaacTBeast, 13 March 2014 - 08:24 AM
IsaacTBeast #1
Posted 13 March 2014 - 09:24 AM
Hello guys I need help because of this code


function main()
  term.setBackgroundColor(colors.white)
  term.clear()
  term.setCursorPos(1,1)
  os.sleep(0.1)
  while true do
    term.setBackgroundColor(colors.lightBlue)
    term.clear()
    paintutils.drawLine(1, 1, screenX, 1, colors.cyan)
    term.setTextColor(colors.black)
    term.setCursorPos(1,1)
    print("System Applications")
    term.setBackgroundColor(colors.lightBlue)   
    term.setTextColor(colors.black)
    term.setCursorPos(1,4)
    print("[CMD]")
    term.setBackgroundColor(colors.lightBlue)
    term.setTextColor(colors.black)
    term.setCursorPos(1, 3)
    print("(Test Mouse Work)")
    term.setBackgroundColor(colors.cyan)
    term.setCursorPos(40,1)
    term.setTextColor(colors.black)
    print("[X]")
    local event, button, X, Y = os.pullEventRaw("mouse_click")
	 if X >= 1 and X <=  and Y == 1 and button == 1 then
	    print("Test Mouse")
	    sleep(0.5)
	    loop()
	  elseif X >= 1 and X <= 10 and Y == 4 and button == 1 then
	    sleep(0.5)
	    shell.run("/isaacos/Programs/cmd.lua")
	  elseif X >= 40 and X <= 43 and Y == 1 and button == 1 then
	    sleep(0.5)
	    shell.run("/isaacos/system/x16/os.lua")
		
	
	  end


  end
end

function loop()
term.clear()
sleep(0.5)
main()
end

main()

screenX, screenY = term.getSize()

it says the paintutils:45: bad argument: double expected, got nil
oeed #2
Posted 13 March 2014 - 10:38 AM
You haven't assigned screenX to anything.

When this is run screenX is nil because you haven't set it.

paintutils.drawLine(1, 1, screenX, 1, colors.cyan)

You need to move this (note you should add local to the front) to the top. It's never called because main starts before it is.

local screenX, screenY = term.getSize()

Although, it's probably better to use screenW or screenWidth, so it's more obvious.
Edited on 13 March 2014 - 09:41 AM
joebodo #3
Posted 13 March 2014 - 10:43 AM
Hello guys I need help because of this code

You were pretty close. Here's what you need to change:

line 26:
if X >= 1 and X <= screenX and Y == 1 and button == 1 then

lines 50-51:
screenX, screenY = term.getSize()  -- << This line needs to be before calling main
main()

Edit: too slow
Edited on 13 March 2014 - 09:45 AM