Page 1 of 1

HELP if statement problem

Posted: Sat Apr 04, 2015 1:12 pm
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 ?

Re: HELP if statement problem

Posted: Sat Apr 04, 2015 2:32 pm
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.

Re: HELP if statement problem

Posted: Sat Apr 04, 2015 4:58 pm
by Mateus
Hello, I solved problem by my own, exactly how you would do it as I see.
Sorry for breaking rules...

Thanks !