Page 1 of 1

Hovering problem

Posted: Mon May 25, 2015 7:34 pm
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 :)

Re: Hovering problem

Posted: Mon May 25, 2015 7:50 pm
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

Re: Hovering problem

Posted: Mon May 25, 2015 8:05 pm
by dawi98
Thank you for a fast reply its working so as i wanted :D Thanksssss