Computer Science Canada Keeping the lights on/off |
Author: | RahulPatel23 [ Fri May 17, 2013 9:39 am ] | ||
Post subject: | Keeping the lights on/off | ||
What is it you are trying to achieve? I have to simulate a program that would allow you to remotely turn on/off lights for my Computer Engineering culminating assignment. This is my first semester coding so I apologize in advance for any stupid mistakes i make ![]() Thanks in advance ![]() What is the problem you are having? Whenever I click to turn the lights on they immediately reset to "off" Describe what you have tried to solve this problem Tried removing various loops and cls's but thats about it. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
|
Author: | Raknarg [ Fri May 17, 2013 9:53 am ] | ||
Post subject: | RE:Keeping the lights on/off | ||
Throw in a boolean statement that keeps track of whether the lights have been turned on or off. That way you can change how the drawing works too. You draw according to what your booleans are. For instance, for your green bed could be something like this:
I made a functional program for you, but I don't quite want to give it to you yet, I'd rather you try to figure it out first. Feel free to ask any other questions |
Author: | TW iz Rippin [ Fri May 17, 2013 10:50 am ] |
Post subject: | RE:Keeping the lights on/off |
No! Don't do a boolean! The problem is that every time the loop runs through, it resets the colours to defuallt: var livingcolour, bedcolour : int livingcolour := 118 bedcolour := 113 those lines should be at the start of your program, rather than inside the main loop. Then when you click a different box, other than the one that is lit, recolour the box that was already lit. |
Author: | Raknarg [ Fri May 17, 2013 11:45 am ] |
Post subject: | RE:Keeping the lights on/off |
Yes, but it makes more sense to use a boolean to keep track of your lights. Anyways, either way it'll be the same thing... basically make sure you state your variables outside the loop unless you have a good reason for doing so. |
Author: | RahulPatel23 [ Fri May 17, 2013 2:09 pm ] |
Post subject: | RE:Keeping the lights on/off |
Alright thanks guys I will be sure to try your fixes when i get to class Rahul |
Author: | RahulPatel23 [ Sat May 18, 2013 4:25 pm ] |
Post subject: | RE:Keeping the lights on/off |
@Tw iz Rippin I tried putting the variables out side the loop and they can stay on, but if i want turn them back off, i can't. |
Author: | RahulPatel23 [ Sat May 18, 2013 4:26 pm ] |
Post subject: | Re: RE:Keeping the lights on/off |
Raknarg @ Fri May 17, 2013 9:53 am wrote: Throw in a boolean statement that keeps track of whether the lights have been turned on or off.
That way you can change how the drawing works too. You draw according to what your booleans are. i tried using booleans but im slightly confused ![]() Rahul |
Author: | Nathan4102 [ Sat May 18, 2013 5:01 pm ] | ||||
Post subject: | RE:Keeping the lights on/off | ||||
A boolean is a variable type, much like a string or an integer. You create a boolean variable the same way you create other variables:
Booleans have two states: true, or false(No caps). They can be assigned states just like other variables:
You can use this to control weather your lights are on or off. Make sense now? |
Author: | RahulPatel23 [ Tue May 21, 2013 1:07 pm ] | ||
Post subject: | RE:Keeping the lights on/off | ||
alright so i tried using a boolean for my livingroom lights but turing keeps saying "syntax error at ':=' expected 'then'" setscreen ("graphics") var font : int font := Font.New ("serif:6")
any help?? |
Author: | Nathan4102 [ Tue May 21, 2013 1:22 pm ] |
Post subject: | RE:Keeping the lights on/off |
When comparing two things (In this case, "onoroff" and "false"), you need to use =. := is for assignment, when you want to assign a variable a value. |
Author: | RahulPatel23 [ Tue May 21, 2013 1:41 pm ] | ||
Post subject: | Re: Keeping the lights on/off | ||
so i figured out how to do the booleans but when i click the respective areas sometimes the lights wont toggle and will just flicker. Also when it is successful when the toggle is happening there is still some flicker. Are there any fixes for it? |
Author: | Raknarg [ Wed May 22, 2013 10:04 am ] |
Post subject: | RE:Keeping the lights on/off |
Yes. Let's say you press the button, and then the loop loops twice before you let go. The first time it goes through, it'll turn a light on. However, it will go through it again and then turn it off. So the problem is that you have to find a way to make it so that the program only turns the button on or off once while you're clicking, or when you let go of the button. |
Author: | RahulPatel23 [ Wed May 22, 2013 10:25 am ] | ||
Post subject: | RE:Keeping the lights on/off | ||
alright here is the final code all i did to fix the flickering was add a delay at the end of the loop. Thanks for all of your help guys ![]() |