HELP if statement problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

HELP if statement problem

Post by Mateus »

Hello, I have a weird problem,
code :

Code: Select all

function casesUpdate()
	if getPressed() == 'Case1' then
		selectedCase = images.cases.case1
		first = true
		load = 'case_open'
	end
	if getPressed() == 'Case2' then
		selectedCase = images.cases.case2
		first = true
		load = 'case_open'
	end
.. code continues..
If I click Case1 in game, it does someting, but Case2 does nothing (getPressed() always returns correctly).
Simply, it only reacts on a first if statement. If I put Case2 as first if, it only reacts to Case2. Any help please ?
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: HELP if statement problem

Post by undef »

This post rather belongs to the "Support and Development" forum and as stated in the posting rules, you should add a .love file if you want any help.

You're code is not as one would usually write it, this is more common:

Code: Select all

function casesUpdate()
    local pressed = getPressed()
    if pressed == 'Case1' then
       selectedCase = images.cases.case1
    elseif pressed == 'Case2' then
       selectedCase = images.cases.case2
    end
    first = true
    load = 'case_open'
end
In case this solves your problem, think about why it does, otherwise that error might happen again.
twitter | steam | indieDB

Check out quadrant on Steam!
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: HELP if statement problem

Post by Mateus »

Hello, I solved problem by my own, exactly how you would do it as I see.
Sorry for breaking rules...

Thanks !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest