Skip to content
Advertisement

Boolean flags aren’t corresponding to the switch they are in

I’m trying to make a traffic simulator and I completely underestimated how hard it was going to be to get all the classes to work together. I’ve finally gotten all the functions to work quite well, and am now I’m trying to put them together. On my lights algorithm I’ve gotten the lights to change fine on a timer, but then I needed to tie in a boolean that was attached to the lights color and then use it outside that class to tell the car to move or not (Failed Miserably). So now I’ve brought the Car classes .move/.draw to the lights class instead, although for some reason the booleans won’t correspond to the switch their in although there’s a variable that changes the light so I don’t see why my boolean continually switches from true to false when the lights in that switch are staying the same I’ve put in println to show how the lights are changing fine but the flags arent. I’ve commented out a couple different places I’ve tried placing the car.draw sections.

I’ve edited the code to just resemble how the boolean flags aren’t corresponding with the lights changing.

Also if I can get the flags to work how can I call upon that flag in another class?

JavaScript

Advertisement

Answer

I was using !X to represent false. SOLVED. Revised class code posted below, for a light switch that includes green, yellow, and red lights.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement