PDA

View Full Version : toggle a script on and off


arshlevon
10-13-2005, 02:40 PM
i was wondering if there was a way to toggle a script with one key? i have a simple little script that makes the light amount 0.. this is to make the character i am working on completely black so i can check the silloette and make sure it reads well from a distance.. now i can turn the light level back up to 1 with a new script and assign it to a different key.. but i was wondering if there was way to assign it to a key that toggles the light level from 0 back to 1 again?? and info on making something toggle would be great..

Light
10-13-2005, 02:58 PM
Samuel,

Maybe this does what you need:

if $.multiplier == 0 then $.multiplier = 1 else $.multiplier = 0





Light

j-man
10-13-2005, 03:03 PM
yes!


global lightstatus
if lightstatus==undefined then
(
makeeverythingdark script
lightstaus=1
) else
(
makeeverythinglight script
lightstatus=undefined
)


Does this make sense? save this script as a macroscript and assign it to a button of your choice.

bye!

Josh.

j-man
10-13-2005, 03:05 PM
if $.multiplier == 0 then $.multiplier = 1 else $.multiplier = 0

ah-hem,

if light then no light else let there be light

?

J

Light
10-13-2005, 03:12 PM
ah-hem,

if light then no light else let there be light

?

J

You really have some creative coding skills there! :thumbsup:




Light

arshlevon
10-13-2005, 05:24 PM
okay i cant seem to get it to work.. it makes everything black.. but it dosent seem turn the lights back on when i hit the key again.. here is what i used.. maybe i did something wrong??



global lightstatus
if lightstatus==undefined then
(
lightLevel = 0
lightstaus=1
) else
(
lightLevel = 1
lightstatus=undefined
)

pindercarl
10-13-2005, 09:57 PM
You're missing a 't' in the line: "lightstaus=1" so you aren't ever changing the value of the global variable lightstatus.

arshlevon
10-14-2005, 07:49 AM
thanks.. i feel dumb not seeing that.. but the script still dosent work.. it toggels the lights off but dosent bring them back on..

Moosley
10-14-2005, 10:26 AM
macroScript LightTools
category:"Light Tools"
toolTip:"Turn all lights on/off"
icon:#("Lights",3)

(
lightsOn = true
on execute do
(
if lightsOn then lights.enabled = false
else lights.enabled = true
lightsOn = not lightsOn
)

)


Run that and bind to a key, that should do it (hopefully! :))

Wahooney
10-14-2005, 12:25 PM
Rather than using the light multiplier, which you might be adjusting to values not equal to 1, just switch the lights on and off.

macroscript lightsToggle
category:"Wahooney Tools"
tooltip:"Toggle Lights On\Off"
(
global bLightStatus = true

on execute do
(
bLightStatus = not bLightStatus
lights.on = bLightStatus
)
)

Moosley
10-14-2005, 12:40 PM
Snap! Do I win 5 ? :)

Wahooney
10-14-2005, 12:48 PM
Good grief!!! I didn't even read your post! Read the first few then posted. That's quite shocking!

arshlevon
10-14-2005, 05:51 PM
thanks guys! such a dumb little thing.. but now i see how toggling works and i am sure it will come in use in the future..

Wahooney
10-17-2005, 01:09 PM
I took the script a few steps further, not the toolbar button will check on and off to show the light status, and any lights that are created will be set to the current toggle state. ie If the lights are toggled off any lights that are copied, cloned or merged will be turned off.

Here's the code:
macroScript lightsToggle
category:"Wahooney Tools"
tooltip:"Toggle Lights On\Off"
buttonText:"Lights off"
(
global lightStatus = true
global LightToggleCB

fn LightToggleCB =
(
n = callbacks.notificationParam()

if superclassof n == light then
n.on = lightStatus
)

on execute do
(
lightStatus = not lightStatus
lights.on = lightStatus
)

on isChecked do
(
not lightStatus
)

callbacks.removeScripts id:#wtToggleLights
callbacks.addScript #sceneNodeAdded "LightToggleCB()" id:#wtToggleLights
)

CGTalk Moderation
10-17-2005, 01:09 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.