I am creating an options menu for a simple game. I want to make a button that will adjust my lamps energy up or down.
I would like both ways, a button that adjust the lamp energy up and a way to adjust it down.
scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() light = scene.lights['Lamp'] if cont.sensors['Mouse1'].hitObject.name == 'button.up' and cont.sensors['Lclick'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_JUST_ACTIVATED: light.energy += 0.5 if cont.sensors['Mouse1'].hitObject.name == 'button.down' and cont.sensors['Lclick'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_JUST_ACTIVATED: light.energy -= 0.5
Attach this script to your two buttons with these logic bricks. The two buttons must be named
button.up, or you will have to change the names in the script.
The two buttons will increase and decrease the default
Lamp energy by
0.5 per click.
The "I'm not a programmer!" approach.
First step: Create the button(s), create the light.
Second Step: Create an animation for the lamp where it is dim at frame 1 and bright at frame 200.
Third Step: Switch to game logic and add a property to the light named Bright. Make an action actuator with the play mode set to property set the property and the frame property of the actuator to be Bright. Do the rest of the setup as follows.
This basically means If the mouse is over the button (cube) and the mouse is clicked, add two to the Bright property. Play the PointAction as Bright is increased.
Forth step: (optional) Add an always sensor and a mouse visibility if your game has no way of knowing where the mouse is. Create another button with the exact same setup except make the property Bright decrease by two under the property actuator