Evaluation skipped?

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
mastastealth
Prole
Posts: 30
Joined: Thu Jul 03, 2008 2:44 am
Location: Barranquilla, Colombia
Contact:

Evaluation skipped?

Post by mastastealth » Tue Jul 08, 2008 2:44 am

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?

User avatar
farvardin
Party member
Posts: 162
Joined: Sat Jun 28, 2008 6:46 pm

Re: Evaluation skipped?

Post by farvardin » Tue Jul 08, 2008 5:19 am

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)

User avatar
rude
Administrator
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Evaluation skipped?

Post by rude » Tue Jul 08, 2008 6:34 am

Hmm, what does hira_vowels.png and hira_k.png look like, and what is KanaColumn() supposed to do?

User avatar
mastastealth
Prole
Posts: 30
Joined: Thu Jul 03, 2008 2:44 am
Location: Barranquilla, Colombia
Contact:

Re: Evaluation skipped?

Post by mastastealth » Tue Jul 08, 2008 7:47 pm

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.
Attachments
LoveKana.zip
(21.34 KiB) Downloaded 127 times

User avatar
zeddy
Prole
Posts: 8
Joined: Mon Jul 07, 2008 11:03 am

Re: Evaluation skipped?

Post by zeddy » Tue Jul 08, 2008 8:47 pm

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 ^^

User avatar
mastastealth
Prole
Posts: 30
Joined: Thu Jul 03, 2008 2:44 am
Location: Barranquilla, Colombia
Contact:

Re: Evaluation skipped?

Post by mastastealth » Tue Jul 08, 2008 11:30 pm

Ah! Ok, that works, nice catch. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests