I am trying to develop a game where you can draw, but when you press a button you can’t draw anymore. I tried some things like isVisible = false and stuff like that but it did not work. please help
I’m a newbie to coding so my solutions are simple but not elegant.
try using an if statement and flag combination.
so within your draw function the guts of it is enclosed within an if statement
function
if drawOk == true then….
DRAW
end
end
Your button pressed makes drawOk = false.
T.
It’s even simpler than that, but ToeKnee has the right idea.
local canDraw = true function drawstuff() if canDraw then -- draw stuff end end -- In lua, you don't have to say == true. -- likewise, if you want to say something == false or == nil, just say 'not'
@richard9 - just tried that - pretty good for 2 outcome conditionals.
Thanks for the little lesson.
T.
This is easy to test using your terminal output with a print statement
Do a simple function like richard9’s drawstuff() just use a print call instead of – draw stuff and test it with if & if not.
Then watch your terminal. Thats the best way to learn.
But in answer to your Q - yes.
T.
Hey great advice.
It’s still not intuitive for me to check the terminal on these things and that was a great reminder.
Thank you very much.
I’m a newbie to coding so my solutions are simple but not elegant.
try using an if statement and flag combination.
so within your draw function the guts of it is enclosed within an if statement
function
if drawOk == true then….
DRAW
end
end
Your button pressed makes drawOk = false.
T.
It’s even simpler than that, but ToeKnee has the right idea.
local canDraw = true function drawstuff() if canDraw then -- draw stuff end end -- In lua, you don't have to say == true. -- likewise, if you want to say something == false or == nil, just say 'not'
@richard9 - just tried that - pretty good for 2 outcome conditionals.
Thanks for the little lesson.
T.
This is easy to test using your terminal output with a print statement
Do a simple function like richard9’s drawstuff() just use a print call instead of – draw stuff and test it with if & if not.
Then watch your terminal. Thats the best way to learn.
But in answer to your Q - yes.
T.
Hey great advice.
It’s still not intuitive for me to check the terminal on these things and that was a great reminder.
Thank you very much.