Jump to content




Menu system not working


16 replies to this topic

#1 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:16 AM

This code isn't working right:
local event, button, x, y = os.pullEvent("mouse_click")
    if event == "mouse_click" then
	 if x == 1 or x == 2 or x == 3 or x == 4 or x == 5 or x == 6 or x == 7 or x == 8 then
	  if y == 2 then --option 1

	  else
	 
	  if y == 3 then --option 2

	  else
	 
	  if y == 4 then -- option 3

I have tried elseif and if but they both do the same thing, if you click the first option it works, if you click 2 or 3 it doesn't.

#2 Doyle3694

  • Members
  • 815 posts

Posted 30 January 2013 - 06:19 AM

you lack.... 4 ends. Also, this was a obvious bug. But you got to give us the error it returns.

#3 OmegaVest

  • Members
  • 436 posts

Posted 30 January 2013 - 06:20 AM

Query: What are you doing to test this? Or rather, what are the contents of the if blocks?

It may not be the conditional statements that are failing, but something within them that is causing them to break instead of going to the next conditional.

#4 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:21 AM

There is no error, it just doesn't work. Like i said, and i have all the ends in my program.

#5 Doyle3694

  • Members
  • 815 posts

Posted 30 January 2013 - 06:23 AM

Can you quote yourself where you say all the ends are in the program? And maybe you should give us some info? I recon "This code isn't working right" is not enough. Also, post full code. Can't stress that enough. We need full code to help you.

#6 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:24 AM

 OmegaVest, on 30 January 2013 - 06:20 AM, said:

Query: What are you doing to test this? Or rather, what are the contents of the if blocks?

It may not be the conditional statements that are failing, but something within them that is causing them to break instead of going to the next conditional.
I don't understand. English please. My coding skills aren't that great, and I don't talk THAT geeky.

#7 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 30 January 2013 - 06:25 AM

And why don't you use "elseif's" instead?

#8 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:26 AM

 Doyle3694, on 30 January 2013 - 06:23 AM, said:

Can you quote yourself where you say all the ends are in the program? And maybe you should give us some info? I recon "This code isn't working right" is not enough. Also, post full code. Can't stress that enough. We need full code to help you.
--Vars
ver = "0.0.1"
function drawDesktopBackground(x, y)
desktopBackground = paintutils.loadImage("//.sys/background")
paintutils.drawImage(desktopBackground, x, y)
end
totalTicks = 0 --Resets tick counter
--Main loop
while true do
totalTicks = totalTicks + 1 --Tick counter
term.setBackgroundColor(colors.white)
term.clear()
drawDesktopBackground(13, 2) --Draws desktop background
paintutils.drawLine(1, 1, 99, 1, colors.gray) --Draws menu bar
term.setTextColor(colors.black)
term.setCursorPos(1, 1)
print("[Menu]							Total Ticks:", totalTicks) --Draws menu button and tick counter
local event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  if x == 1 or x == 2 or x == 3 or x == 4 or x == 5 or x == 6 then
   if y == 1 then
	paintutils.drawLine(1, 1, 6, 1, colors.lightGray)
	paintutils.drawLine(1, 2, 8, 2, colors.lightGray)
	paintutils.drawLine(1, 3, 8, 3, colors.lightGray)
	paintutils.drawLine(1, 4, 8, 4, colors.lightGray)
	term.setCursorPos(1, 1)
	print("[Menu]")
	print("Programs")
	print("Settings")
	print("Run")
	local event, button, x, y = os.pullEvent("mouse_click")
	if event == "mouse_click" then
	 if x == 1 or x == 2 or x == 3 or x == 4 or x == 5 or x == 6 or x == 7 or x == 8 then
	  if y == 2 then --Programs
	   term.setBackgroundColor(colors.white)
	   term.clear()
	   paintutils.drawLine(1, 1, 99, 1, colors.gray)
	   term.setTextColor(colors.black)
	   term.setCursorPos(1, 1)
	   print("[Close]							Total Ticks:", totalTicks)
	   paintutils.drawLine(17, 10, 24, 10, colors.white)
	   term.setCursorPos(17, 10)
	   print("Nothing to display")
	   while true do
		local event, button, x, y = os.pullEvent("mouse_click")
		if event == "mouse_click" then
		 if x == 1 or x == 2 or x == 3 or x == 4 or x == 5 or x == 6 or x == 7 then
		  if y == 1 then
		   break
	  else
	
	  if y == 3 then --Settings
	   print("TEST")
	   sleep(3)
	  else
	
	  if y == 4 then --Run
	   term.setBackgroundColor(colors.white)
	   term.clear()
	   paintutils.drawLine(1, 1, 99, 1, colors.gray)
	   term.setTextColor(colors.black)
	   term.setCursorPos(1, 1)
	   print("								  Total Ticks:", totalTicks)
	   paintutils.drawLine(17, 10, 24, 10, colors.white)
	   term.setCursorPos(17, 10)
	   write("Run: ")
	   runcmd = read()
	   shell.run(runcmd)
	
		  end
		 end
		end
	   end
	  end
	 end end
	end	 end
   end
  end
end
end

 Hellkid98, on 30 January 2013 - 06:25 AM, said:

And why don't you use "elseif's" instead?
I said I tried that.

#9 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:39 AM

Just messed with the code some more: found out that it handles options 2 and 3 as if you were clicking off the menu to close the menu. Something is badly wrong.

#10 Doyle3694

  • Members
  • 815 posts

Posted 30 January 2013 - 06:46 AM

all your ends are at the bottom. Place them properly and say if it works :)

#11 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 30 January 2013 - 06:49 AM

Oh sorry did'nt read that..

#12 OmegaVest

  • Members
  • 436 posts

Posted 30 January 2013 - 06:49 AM

 Doyle3694, on 30 January 2013 - 06:46 AM, said:

all your ends are at the bottom. Place them properly and say if it works :)

Thing is, they are placed properly, since he di elses instead of elseifs. You would cut down on the amount of ends with elseifs, and if it does the same thing, smaller is better. Easier to handle.

#13 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 30 January 2013 - 06:52 AM

Tested proper ends, still does the same thing.

#14 Doyle3694

  • Members
  • 815 posts

Posted 30 January 2013 - 06:58 AM

can you post your code with proper ends?

#15 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 30 January 2013 - 07:21 AM

You had the elseif's in the wrong place.

--Vars
ver = "0.0.1"
screenX, screenY = term.getSize()

function drawDesktopBackground(x, y)
desktopBackground = paintutils.loadImage("//.sys/background")
paintutils.drawImage(desktopBackground, x, y)
end
totalTicks = 0 --Resets tick counter

--Main loop
while true do
	totalTicks = totalTicks + 1 --Tick counter
	term.setBackgroundColor(colors.white)
	term.clear()
	--drawDesktopBackground(13, 2) --Draws desktop background
	paintutils.drawLine(1, 1, 99, 1, colors.gray) --Draws menu bar
	term.setTextColor(colors.black)
	term.setCursorPos(1, 1)
	print("[Menu]")
	local event, button, x, y = os.pullEvent("mouse_click")
	if event == "mouse_click" then
		if x >= 1 and x <= 6 then
			if y == 1 then
				paintutils.drawLine(1, 1, 6, 1, colors.lightGray)
				paintutils.drawLine(1, 2, 8, 2, colors.lightGray)
				paintutils.drawLine(1, 3, 8, 3, colors.lightGray)
				paintutils.drawLine(1, 4, 8, 4, colors.lightGray)
				term.setCursorPos(1, 1)
				print("[Menu]")
				print("Programs")
				print("Settings")
				print("Run")
				b = false
				local event, button, x, y = os.pullEvent("mouse_click")
				if event == "mouse_click" then
					if x >= 1 and x <= 8 then
						term.setBackgroundColor(colors.white)
						term.clear()
						paintutils.drawLine(1, 1, screenX, 1, colors.gray)
						term.setTextColor(colors.black)
						term.setBackgroundColour(colours.white)
						term.setCursorPos(17, 10)
						if y == 2 then --Programs
							b = true
							print("Nothing to display")
						elseif y == 3 then -- settings
							b = true
							print("TEST")
						elseif y == 4 then -- run
							b = true
							write("Run: ")
							runcmd = read()
							shell.run(runcmd)
						end
						if b then
							term.setCursorPos(1, 1)
							term.setBackgroundColour(colours.grey)
							print("[Close]")
							while true do
								_, but, x, y = os.pullEvent("mouse_click")
								if x >= 1 and x <= 7 then -- To close!
									break
								end
							end
						end
					end
				end
			end
		end
	end
end


#16 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 31 January 2013 - 06:51 AM

Thank you!!!!!! It works!!!!!!

#17 Persona

  • Members
  • 12 posts

Posted 03 June 2013 - 01:20 AM

The OS looks and sounds pretty good. Good luck. :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users