We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im trying to get this sequence of code to work but im struggling. The door should open at a random time between 180 and 480 but then close, but for some reason the timer isn't restarting itself and the door just stays open. The player should also not enter the door until it has opened, otherwise pressing the right arrow will not make it move further.
Answers
You confused things a bit :
doorCounter
is your maximumYou need another variable
doorCount++;
that you increase at the end ofdraw()
.also, you could use
millis()
Names
Find also better names like doorCounter and doorCounterMaximum or so
Remarks
also the door should stay open for some time like 200 and close
You can also animate the door opening graphically
so Im a bit confused and that might be due to my limit knowledge.
I have the random integer between 180 and 480 so the door can randomly open between 3 to 8 seconds, (60 frames for second)
after the if statement and the code for the door to open should I put a else statement with the code for the closed door
it doesn't have to be very animated.
im just having trouble with the counter so the door can open and close not only once
this what I've got so far
doorCount ++;
Outside if or else!
added to the last code of draw, door opens within the limit but still doesn't close after it opens, UGHHHHHH
So, good progress here!
When the door is open you would reset
doorCount
to0
as I wrote above.But then the door would close immediately. Bad.
you could set a new boolean variable to false before
setup()
:Set it
true
when door opens.Also before
setup()
:Outside the big if and else section above make a new if clause:
not tested....
okay ive added all you've said, added the statement after the if and else, still keeping the doorCount ++; in the last line in draw.
when I set boolean doorIsOpen = false; same thing again, door opens, never closes
when I set boolean doorIsOpen = true; the door opening flashes for one second, then finally opens again, stay open but again never closes
Then debug it...
you need to reset the variables before using them again. All of them.
Think it through and find the error
I am not at home and can’t do it here
Post your entire code
Do you have this:
doorIsOpen = true;
sorry man
maybe ive been looking at it too much without a break I can't get around the issue
I do have that, no change with it
Set
doorIsOpen
to true after line 35.THANK YOU SO MUCH, it worked lol, so annoying
;-)