permanent variable or: transfer between functions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Chrisblue
Prole
Posts: 5
Joined: Sat Jan 12, 2013 1:10 pm

permanent variable or: transfer between functions

Post 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. ^^
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: permanent variable or: transfer between functions

Post by Robin »

Could you upload a .love of your game? That way, it will be much easier for us to help you.
Help us help you: attach a .love.
User avatar
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: permanent variable or: transfer between functions

Post by master both »

Thats odd, are you sure you dont have any statment "active = false" in the main loop?
User avatar
Chrisblue
Prole
Posts: 5
Joined: Sat Jan 12, 2013 1:10 pm

Re: permanent variable or: transfer between functions

Post 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:
Post Reply

Who is online

Users browsing this forum: Semrush [Bot], zingo and 1 guest