Hovering problem

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
dawi98
Prole
Posts: 2
Joined: Mon May 25, 2015 7:21 pm

Hovering problem

Post by dawi98 »

Hey guys, i have a problem with hovering.

Code: Select all

if x >= terrain[i][4] and x <= terrain[i][4]+128 and y <= 620 then
				--print("ID Terenu: ".. terrain[i][1])
				terrainInfo = "ID: ".. terrain[i][1] .."   |   Owner: ".. terrain[i][5] .."   |   Gold per turn: " .. terrain[i][6] .. "   |   Weather: " .. terrain[i][7] .. " / " .. terrain[i][8]
			else
				terrainInfo = "Hover over the terrain to see info of it!"
			end	
This code should, when hovering the rectangles change the string 'terrainInfo', to formated one with details, and it does but only on the last one item from the table. Tested it with the print(terrain[1]), and it's returning the good value/id, working good in console. In my other code from another game it's working good, i have no idea what im i doing wrong. Can someone help me with this? Was searching on forum but didnt find an answer.

Sorry for my bad english :)
Attachments
simulation.love
game file
(1.57 KiB) Downloaded 39 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Hovering problem

Post by Robin »

Well, yeah, you keep overwriting the variable terrainInfo.

Code: Select all

function game.CheckCursorAllTime(x,y)
	x, y = love.mouse.getPosition()
	terrainInfo = "Hover over the terrain to see info of it!"
	for i=1, #terrain do
			if x >= terrain[i][4] and x <= terrain[i][4]+128 and y <= 620 then
				--print("ID Terenu: ".. terrain[i][1])
				terrainInfo = "ID: ".. terrain[i][1] .."   |   Owner: ".. terrain[i][5] .."   |   Gold per turn: " .. terrain[i][6] .. "   |   Weather: " .. terrain[i][7] .. " / " .. terrain[i][8]
			end	
	end
end
Attachments
simulation.love
fixed
(1.52 KiB) Downloaded 47 times
Help us help you: attach a .love.
dawi98
Prole
Posts: 2
Joined: Mon May 25, 2015 7:21 pm

Re: Hovering problem

Post by dawi98 »

Thank you for a fast reply its working so as i wanted :D Thanksssss
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 81 guests