Page 1 of 1

permanent variable or: transfer between functions

Posted: Mon Jan 14, 2013 6:39 pm
by Chrisblue
Hello everybody. :nyu:
I have a new problem with my function for a selection box, which looks like this:

Image

The problem is, that all entries are only visible, as long as the left mouse button is pressed down.

The code for this action is the following:

Code: Select all

		if love.mouse.isDown("l") then
			love.audio.play(sound)
			y2 = y
			active = true
			love.timer.sleep(0.1)
		end
The variable "active" is only true, as long as the left mouse button is pressed down.
Is there any possibility to make the action permanent, and not just temporary?

The complete code is the following (The draws are all correct. You can ignore them):

Code: Select all

function GUI_select(selections,x,y)
width = 160
love.graphics.setColor(33,33,33)
love.graphics.rectangle("fill", x, y, width, 32)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("line", x - 1, y - 1, width + 2, 34)
love.graphics.line(x+width - 25, y, x+width - 25, y+33)
x = x-4
	if mx > (x+width-25) and mx < (x + width) and my > (y) and my < y + 32 then
	love.graphics.setColor(255,255,0)
		if love.mouse.isDown("l") then
			love.audio.play(sound)
			y2 = y
			active = true
			love.timer.sleep(0.1)
		end
	else
	love.graphics.setColor(255,255,255)
	end
love.graphics.triangle("line", x+width - 16, y + 12, x+width, y + 12, x+width - 8, y + 20)
love.graphics.triangle("fill", x+width - 16, y + 12, x+width, y + 12, x+width - 8, y + 20)
love.graphics.setColor(255,255,255)
love.graphics.print("Test!", x  + 16, y + (height - 17)/2 - 4)

	if active == true then
		for selection, s in ipairs(selections) do
			y2 = y2 + 32
			love.graphics.setColor(33,33,33)
			love.graphics.rectangle("fill", x+4, y2, width, 32)
			love.graphics.setColor(0,0,0)
			love.graphics.line(x+4, y2, x+4+width, y2)
			love.graphics.setColor(255,255,255)
			love.graphics.print(s, x  + 16, y2 + (height - 17)/2 - 4)
		end
	end
end
I would be very thankful for any help. ^^

Re: permanent variable or: transfer between functions

Posted: Mon Jan 14, 2013 7:49 pm
by Robin
Could you upload a .love of your game? That way, it will be much easier for us to help you.

Re: permanent variable or: transfer between functions

Posted: Mon Jan 14, 2013 7:52 pm
by master both
Thats odd, are you sure you dont have any statment "active = false" in the main loop?

Re: permanent variable or: transfer between functions

Posted: Mon Jan 14, 2013 8:33 pm
by Chrisblue
I just fixed the problem by my own. :D

It was because of the y2= y statement, which moved the selection menu down in a really small amount of time.
I totally thinked wrong and even doubted on the variables, but it was just another small mistake. :o: