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

[help] [Right click menu, "sRM" add the menus of my choice.. not working correct?]

Started by Goof, 06 January 2013 - 08:40 AM
Goof #1
Posted 06 January 2013 - 09:40 AM
Hello :D/>

two "i am trying to" xD :o/>
|
V
I am trying to improve my right click menu a bit..
i am trying to make a function, which add's a right click menu, with the menus, i want..
when i call the "sRM" (screen Right-Menu) then i type in this ( in a function which looks for the right mouse button to be pressed:

		 -- the first two args has to be the X, and Y chors, for the menu..
sRM(xM1, yM1, black, white, "Stop", "Test") -- the last args, has to be the menus i want to add.. ( i want it so i could add infinite )
						  -- the third and forth arg, has to be the Background and TextColor (the black and white, is made by this local color code)
(the above sRM code is coded into this:


function mouse()
  local event, mB1, xM1, yM1 = os.pullEvent("mouse_click")
	if event == "mouse_click" then
	  if mB1 == 2 then
		sRM(xM1, yM1, black, white, "Stop", "Shop")
	  elseif mB1 == 1 then

	  end
	end
end


color code:


local white, orange, magenta, lightBlue, yellow, lime, pink, gray, lightGray, cyan, purple, blue, brown, green, red, black = colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black
-- This is in ONE line...

and my Add menu function looks like this:


( Please note that the tT, tW, tB, tP functions are written by myself ( will show full code last ) )
Spoiler


function sRM(...) -- XCor, YCor, BacColor, TxtColor, Menus --
  if sRM then
	local tArgs = {...}
	  if #tArgs ~= nil then
		tP(tArgs[1],tArgs[2])
		tB(tArgs[3])
		tT(tArgs[4])
		tW("		  ")
		local x = tArgs[1]
		local y = tArgs[2]
		local aLg = 5
		y = y + 1
		  repeat
			tP(x, y)
			tW(tArgs[aLg])
			y = y + 1
			aLg = aLg + 1
		  until #tArgs == nil

	end
  end
end
Spoiler



function tP(x,y)
  term.setCursorPos(x,y)
end

function tB(color)
  term.setBackgroundColor(color)
end

function tT(color)
  term.setTextColor(color)
end

function tCP(x,y)
  tP(x,y)
  term.write(" ")
end

function tW(txt)
  term.write(txt)
end

function clearL()
  term.clearLine()
end

function clear()
  term.clear()
end


Full Code:
Spoilerthis is only on pastebin..
http://pastebin.com/KKFk9n6b


But… now to the problem..

when i rightclick, it show everything fine.
it shows me this error:
parallel:22: test1:159:
attempt to perform arithemetic __add on table and number

– on pastebin its at line 159 …

and.. i actually knows what the error is, but when the error is solved, then my right click menu still does not work.. ( it kinda mess up the whole screen )
((Thats because i posted my code before solving the attempt issue, so you could get a better knowledge about my code. ))

PS: its pretty hard to explain it more that this, so i cant promise, that i would be able to explain it better. ( about how to make add right menu, etc… )
I hope someone would help me.


Thanks in advance.
remiX #2
Posted 06 January 2013 - 09:44 AM
You're comparing the number of items in the table tArgs which is the argument tables with nil.

Try until #tArgs == 0

edit: also, it will only stop until tArgs has no items left in it, but you never remove items within the table
Goof #3
Posted 06 January 2013 - 09:45 AM
wait a sec.. i will try that…

edit it worked now, but..
i am now trying to make the " " line after the last menu is printed, but why does it not do that ?




function sRM(...) -- XCor, YCor, BacColor, TxtColor, Menus --
  if sRM then
    local tArgs = {...}
      if #tArgs ~= nil then
        tP(tArgs[1],tArgs[2])
        tB(tArgs[3])
        tT(tArgs[4])
        tW("          ")
        local x = tArgs[1]
        local y = tArgs[2] 
        local aLg = 5
        y = y + 1

          repeat
            tP(x, y)
            tW(tArgs[aLg])
            y = y + 1
            aLg = aLg + 1
          until #tArgs == 0
        tP(x,y)
        tW("          ")
      end
  end
end
Exerro #4
Posted 06 January 2013 - 09:46 AM
i had an error like this before…check that the variables arent being changed in other functions or dont use local variables as they can sometimes mess up things and appear as nil
Goof #5
Posted 06 January 2013 - 09:52 AM
i had an error like this before…check that the variables arent being changed in other functions or dont use local variables as they can sometimes mess up things and appear as nil
ehm i know that…

but in my case with this right click menu, i dont need to change the local, because the local variables in the function doesn't have to get out to the rest of the program- :D/>
Goof #6
Posted 06 January 2013 - 10:25 AM
wait a sec.. i will try that…

edit it worked now, but..
i am now trying to make the " " line after the last menu is printed, but why does it not do that ?




function sRM(...) -- XCor, YCor, BacColor, TxtColor, Menus --
  if sRM then
	local tArgs = {...}
	  if #tArgs ~= nil then
		tP(tArgs[1],tArgs[2])
		tB(tArgs[3])
		tT(tArgs[4])
		tW("		  ")
		local x = tArgs[1]
		local y = tArgs[2]
		local aLg = 5
		y = y + 1

		  repeat
			tP(x, y)
			tW(tArgs[aLg])
			y = y + 1
			aLg = aLg + 1
		  until #tArgs == 0
		tP(x,y)
		tW("		  ")
	  end
  end
end

Ehm now i think it looks like, when doing the until #tArgs == 0

it just doesnt break, i think… i will just do that forever.. ( and then i got too long without yielding) so im pretty sure, that the Until does not work…

Thanks…
remiX #7
Posted 06 January 2013 - 11:19 AM
it just doesnt break, i think… i will just do that forever.. ( and then i got too long without yielding) so im pretty sure, that the Until does not work…

edit: also, it will only stop until tArgs has no items left in it, but you never remove items within the table
Goof #8
Posted 06 January 2013 - 01:20 PM
Never mind. I just edited the repeat, to a while. And then i have 1 more arg, before the menu list.

and thats, how many menus, there Are on the specific menu.


but thanks :D/>