This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Goof's profile picture

[lua][api]Code not changing variable.

Started by Goof, 18 April 2013 - 04:18 AM
Goof #1
Posted 18 April 2013 - 06:18 AM
Hello Everyone!


i am trying to make a button, that displays a menu when i click on it. but i also wanted the menu to dissappear, when i click the same icon.. but it doesnt change the
inStartMenu variable.. or it doesnt look like it does.



if butID == 1 or text == "START" and inStartMenu == false then
	button.enableDisplay(true,2,3,4,5,6,7,8,9,10,11,12,13)
	button.drawDisplay(2,3,4,5,6,7,8,9,10,11,12,13)
	inStartMenu = true
        print(inStartMenu)
elseif butID == 1 or text == "START" and inStartMenu == true then  -- this doesnt even run.
	button.visibleDisplay(false,13,12,11,10,9,8,7,6,5,4,3,2)
	button.enableDisplay(false,2,3,4,5,6,7,8,9,10,11,12,13)
	inStartMenu = false
	print(inStartMenu)
end	

Do anyone have any idea on, why it doesnt change the variable?

Thanks in Advance
Bubba #2
Posted 18 April 2013 - 07:40 AM
Can't really help you with such a small portion of the code. I have no idea what those functions do, although I can make an educated guess. I don't know where you get the butID variable from, or where you get the text variable from. I don't know what sets the value of inStartMenu. As far as your if statement goes, I see nothing wrong.
Smiley43210 #3
Posted 18 April 2013 - 07:52 AM
With this little code, the only guess I can make is that the if statement doesn't get past 'or text == "START" and inStartMenu…' because butID = 1. Lua may be interpreting the if condition as "if (butID == 1) or (text == "START" and inStartMenu == false) then", causing it to never check inStartMenu. Try putting parenthesis around the 'butID or text' part.

That's just a guess; not too sure about it.
Bubba #4
Posted 18 April 2013 - 07:55 AM
With this little code, the only guess I can make is that the if statement doesn't get past 'or text == "START" and inStartMenu…' because butID = 1. Lua may be interpreting the if condition as "if (butID == 1) or (text == "START" and inStartMenu == false) then", causing it to never check inStartMenu. Try putting parenthesis around the 'butID or text' part.

That's just a guess; not too sure about it.

Good guess. Didn't think about that.

Lua will indeed evaluate it like this: if (butID == 1) or (text=="START" and inStartMenu == false) then
Perhaps you want it to be evaluated like this: if (butID == 1 or text=="START") and inStartMenu == false then
Goof #5
Posted 18 April 2013 - 06:56 PM
Well, i tried that, and :o/>
it worked! Thanks guys!