Jump to content




Mouse Event draws menu then clears it? [<SOLVED>]


  • You cannot reply to this topic
7 replies to this topic

#1 Mr_Programmer

  • Members
  • 95 posts
  • LocationA CPU some where in Bolton, UK

Posted 03 January 2016 - 02:14 AM

Hi everyone,

i am working on 2 programs at the minute and i am using the same mouse event function to draw menus and what not, one of the programs i have been foring on for over 6+ months and the mouse events worked fine but now it doesnt work propper.

INFO: when the "menu" secection is clicked, it should draw a drop down menu, however, it does do that but when i let go of the mouse button, the menu goes away, i have checked the code and cant see anything wrong with it unless im just not noticing the problem.

Here is the 2 peices of code:

function drawLogMenu()
	term.setBackgroundColour(c_writing)
	term.setTextColour(c_menu)
	term.setCursorPos(33,2)
	print("===================")
	term.setTextColour(c_border)
	term.setCursorPos(33,3)
	print("   Reboot System   ")
	term.setCursorPos(33,4)
	print("				   ")
	term.setCursorPos(33,5)
	print("  Shutdown System  ")
	term.setCursorPos(33,6)
	term.setTextColour(c_menu)
	print("===================")
	term.setCursorPos(43,1)
	term.setTextColour(c_off)
	term.setBackgroundColour(c_error)
	print("System <<")
	term.setBackgroundColour(black)
end

This one is the draw menu and this one:

function login3()
	ls = 0
	logScreen = true

	while logScreen == true do
		local event, button, X, Y = os.pullEventRaw()
		if ls == 0 then
			if event == "mouse_click" then
				if X >=43 and X <=52 and Y == 1 and button == 1 then
					drawLogMenu()
					ls = 1
				elseif X >=21 and X <=38 and Y == 8 and button == 1 then
					logScreen = false
					term.setCursorPos(21,8)
				elseif X >=20 and X <=33 and Y == 15 and button == 1 then
					logScreen = false
					accountCreation()
				elseif X >=38 and X <=51 and Y == 15 and button == 1 then
					logscreen = false
					accountDeletion()
				else
					login()
				end
			end
		elseif ls == 1 then
			if X >=35 and X <=50 and Y == 3 and button == 1 then
				ls = 0
				rednet.send(ServerID, "systemReboot")
				os.reboot()
			elseif X >=34  and X <=51 and Y == 5 and button == 1 then
				ls = 0
				os.shutdown()
			else
				ls = 0
				login()
			end
		end
	end
end

This one is the Mouse event code.


Any help would be muchly appreciated,

Thanks, MrProgrammer...

Edited by Mr_Programmer, 04 January 2016 - 12:43 AM.
- Indentation.


#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 03 January 2016 - 02:30 AM

I think it is because letting go of the mouse queues a "mouse_release" event. Since there is a new event, the whole thing gets drawn again without the drop down part. You have to add a variable isPressed and when it is true then draw the drop down part too.

#3 Mr_Programmer

  • Members
  • 95 posts
  • LocationA CPU some where in Bolton, UK

Posted 03 January 2016 - 02:36 AM

View PostCreator, on 03 January 2016 - 02:30 AM, said:

I think it is because letting go of the mouse queues a "mouse_release" event. Since there is a new event, the whole thing gets drawn again without the drop down part. You have to add a variable isPressed and when it is true then draw the drop down part too.
There is no "mouse_release" on the wiki? im on computercraft 1.7 also if there is a "mouse_release" event there, then there is no where for it to go? it shouldnt wipe the dropDownMenu off the screen? if anything it shouldnt do anything becouse the program hasnt required the event to do anything? does that make sence or does everything i just said wrong?

Edited by Mr_Programmer, 03 January 2016 - 02:56 AM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 03 January 2016 - 02:41 AM

He's referring to mouse_up

#5 Mr_Programmer

  • Members
  • 95 posts
  • LocationA CPU some where in Bolton, UK

Posted 03 January 2016 - 02:45 AM

View PostKingofGamesYami, on 03 January 2016 - 02:41 AM, said:

He's referring to mouse_up
Ah, ok but still why is the event taking effect on the program if the program is only asking for "mouse_click" it shouldnt undraw the menu upon "mouse_up"? or am i incorrect?

#6 Mr_Programmer

  • Members
  • 95 posts
  • LocationA CPU some where in Bolton, UK

Posted 03 January 2016 - 02:54 AM

Would i just be able to change
 if event == "mouse_click" then 

to this? or would it not work?
 if event == "mouse_click" or "mouse_up" then 

or would it be better to just have
 if event == "mouse_up" then 

Edited by Mr_Programmer, 03 January 2016 - 02:55 AM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 January 2016 - 03:04 AM

This certainly wouldn't work:

 if event == "mouse_click" or "mouse_up" then 

You meant:

 if event == "mouse_click" or event == "mouse_up" then 

In your current code, you only check the event type if ls is 0. If ls is 1, you perform no such check.

Seems easiest to simply apply a filter to this line:

local event, button, X, Y = os.pullEventRaw("mouse_click")

os.pullEventRaw() will then ignore all events other than the type you're interested in, and will only return once one of those enters the queue.

#8 Mr_Programmer

  • Members
  • 95 posts
  • LocationA CPU some where in Bolton, UK

Posted 03 January 2016 - 03:34 AM

View PostBomb Bloke, on 03 January 2016 - 03:04 AM, said:

This certainly wouldn't work:

 if event == "mouse_click" or "mouse_up" then 

You meant:

 if event == "mouse_click" or event == "mouse_up" then 

In your current code, you only check the event type if ls is 0. If ls is 1, you perform no such check.

Seems easiest to simply apply a filter to this line:

local event, button, X, Y = os.pullEventRaw("mouse_click")

os.pullEventRaw() will then ignore all events other than the type you're interested in, and will only return once one of those enters the queue.

Thanks, Bomb Bloke, all fixed, thanks a bunch!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users