Page 1 of 1

Evaluation skipped?

Posted: Tue Jul 08, 2008 2:44 am
by mastastealth
Ok, attempting a little Japanese symbol memorization game, here's the code so far

Code: Select all

function KanaColumn(sprite,xpos,ypos,kanalist)
	kana = '' 
	local sprh = sprite:getHeight()
	local sprw = sprite:getWidth()
	if mouseX >= xpos-(sprw/2) and mouseX <= xpos+(sprw/2) then
		if mouseY >= ypos-(sprh/2) and mouseY <= (ypos-(sprh/2))+32 then kana = kanalist[1] end
		if mouseY >= (ypos-(sprh/2))+33 and mouseY <= (ypos-(sprh/2))+64 then kana = kanalist[2] end
		if mouseY >= (ypos-(sprh/2))+65 and mouseY <= (ypos-(sprh/2))+96 then kana = kanalist[3] end
		if mouseY >= (ypos-(sprh/2))+97 and mouseY <= (ypos-(sprh/2))+128 then kana = kanalist[4] end
		if mouseY >= (ypos-(sprh/2))+129 and mouseY <= (ypos-(sprh/2))+160 then kana = kanalist[5] end
	end
end

function load()
	--Images
	bg = love.graphics.newImage("bg.png")
	
	hira1 = love.graphics.newImage("hira_vowels.png")
	hira2 = love.graphics.newImage("hira_k.png")
	
	--Text
	font = love.graphics.newFont(love.default_font, 24)
	love.graphics.setFont(font)
	love.graphics.setColor(0,0,0)
	
	--Word Arrays
	hira_vowels = {"a","e","i","o","u"}
	hira_ks = {"ka","ke","ki","ko","ku"}
end

function update(dt)
	mouseX = love.mouse.getX()
	mouseY = love.mouse.getY()
	
	KanaColumn(hira1,100,240,hira_vowels)
	KanaColumn(hira2,132,240,hira_ks)
end

function draw()
   love.graphics.draw(bg, 320, 240)
   love.graphics.draw(hira1, 100, 240)
   love.graphics.draw(hira2, 132, 240)
   love.graphics.draw(kana, 320,100)   
end
Now, the problem is only the 2 column is being "detected" correctly. The first one doesn't write anything into the "kana" variable anymore, apparently. Something tells me it could be the "lists", does someone see a problem here?

Re: Evaluation skipped?

Posted: Tue Jul 08, 2008 5:19 am
by farvardin
it would be easier if you could provide the full .love file with pictures and such so we could try it for real.

As far as I can understand, it seems with a loop in your KanaColumn function, it may work better... (I may be wrong though)

Re: Evaluation skipped?

Posted: Tue Jul 08, 2008 6:34 am
by rude
Hmm, what does hira_vowels.png and hira_k.png look like, and what is KanaColumn() supposed to do?

Re: Evaluation skipped?

Posted: Tue Jul 08, 2008 7:47 pm
by mastastealth
Oops, yea, I suppose so. Not exactly sure how to make a .love file (just a .zip if I read right somewhere?) so here's a zip with the files.

The 2 hira_x.png's are a 32x160 column, that's 5 squares, 32x32px. KanaColumn should be the detection code that loads each one separately, and detects where along the mouse is hovering over. Each fifth of the column has a variable that will be set into "kana" once it's hovered over.

Re: Evaluation skipped?

Posted: Tue Jul 08, 2008 8:47 pm
by zeddy
Hi,

I had a bit of a look, and i'm fairly sure I know what you're talking about, haha.

In your update() function, you're calling KanaColumn twice:

Code: Select all

function update(dt)
    ...
    KanaColumn(hira1,100,240,hira_vowels)
    KanaColumn(hira2,132,240,hira_ks)
    ...
But at the start of KanaColumn, you're clearing kana:

Code: Select all

function KanaColumn(sprite,xpos,ypos,kanalist)
    kana = ''
    ... 
So that after the second call to KanaColumn, kana is cleared again.

So you could, say remove that line from KanaColumn() and put it in your update() function for example:

Code: Select all

kana = ""
KanaColumn(hira1,100,240,hira_vowels)
KanaColumn(hira2,132,240,hira_ks)
Hope that helps ^^

Re: Evaluation skipped?

Posted: Tue Jul 08, 2008 11:30 pm
by mastastealth
Ah! Ok, that works, nice catch. :D