PDA

View Full Version : Creating a Boolean function to turn on and off a light bulb.


gordee
09-28-2008, 05:15 PM
I already posted this question but nobody has answered and I really need help, so I figured I'd try again with a different name.

Here is my lab:

"Create a world with a lightbulb (lights) and a method turnOnOff that turns the lightbulb on/off depending on whether it is already on/off. When the lightbulb is on, its emissive color property has a value of yellow. When the lightbulb is off, the emissive color is black. Write a Boolean function isLightOn that returns true if he light bulb is on and false if it is off. When clicked, the lightbulb should turn on/off."

Here is what I have done so far:
1. Put the lightbulb into a room setting.
2. Wrote a method turnOnOff that looks like this:
lightbulb: set color to: black
lightbulb: set color to: yellow
3. Created a new event saying:
When mouse is clicked on 'lightbulb', do "lightbulb.turnOnOff"
(I do not know if step #3 was necessary it just seemed like something to do)
4. I started a new function calling it isLightOn. I pressed "Boolean" and now I'm completely stuck!

I need help getting the boolean function to work properly, and I need to know if I am supposed to put the event that I put in.

Thank you! Any help is appreciated! It is due Sunday night. I have a textbook but it really doesn't help me very much.

Gillette Fusion
09-28-2008, 07:51 PM
I'm a little confused on what you need to do . . .

- but Boolean is a fancy way of saying true or false (you probably knew that anyway). I think they want you to make the function something like ~

If (Light bulb = whatever) than
return True
Else
return False

Yeah, something like that.

Confused
10-02-2008, 09:46 PM
I had to do a similar project. Mine had to use a directional light, which was challenging. I set it up like this:

When mouse is clicked on light, do
if: (true) light color = yellow,
then: light set color to black
else: light set color to yellow

Hope this helps!