Ultea Posted February 1, 2021 Share Posted February 1, 2021 I got this working perfectly, then tried to change it, broke it, and forgot how it worked. Now I'm starting over. Basically, I'm trying to get the script to make certain prims visible in a certain sequence when responding to a HUD, and either turn off or on depending on if the prim is already on (cupon), or another linked prim is already on (on). The HUD works fine. The problem is for some reason, despite the script's toggles being set "OFF," the script behaves as if they're "TRUE" when being triggered by the HUD, and it doesn't toggle, it just repeats the same function (power_off()) over and over. power_on(), power_off(), and cup_on just make different prims visible in different colors. I figure I'm missing something obvious but am at my wit's end. Any help would be appreciated. all_off() { llSetLinkPrimitiveParamsFast( LINK_ALL_CHILDREN, [ PRIM_GLOW, ALL_SIDES, 0.0, PRIM_COLOR, ALL_SIDES, white, 0.0 ] ); llSetLinkPrimitiveParamsFast( 3, [ PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 1.0, 1.0]); on = FALSE; cupon = FALSE; } default { state_entry() { llSetLinkPrimitiveParamsFast( LINK_ALL_CHILDREN, [ PRIM_GLOW, ALL_SIDES, 0.0, PRIM_COLOR, ALL_SIDES, white, 0.0 ] ); llSetLinkPrimitiveParamsFast( 3, [ PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 1.0, 1.0]); on = FALSE; cupon = FALSE; HUD_channel=-11*llAbs((integer)("0x"+ llGetSubString(llGetOwner(),0,7))); key owner = llGetOwner(); llListen(HUD_channel,"","",""); } listen( integer channel, string name, key id, string message ) { if( message == "SHUD92" ) { if(on = TRUE) { if(cupon = TRUE) { power_off(); all_off(); } else { power_on(); on = TRUE; cupon = TRUE; } } else if (on = FALSE) { cup_on(); on = TRUE; cupon = TRUE; } } } } Link to comment Share on other sites More sharing options...
Qie Niangao Posted February 1, 2021 Share Posted February 1, 2021 There's some use of the assignment operator (=) when a conditional equal test (==) is wanted. (I didn't check for anything else, but that should be a start.) 1 Link to comment Share on other sites More sharing options...
Ultea Posted February 1, 2021 Author Share Posted February 1, 2021 (edited) Thank you! I knew I missed something obvious. But while that changed the behavior in the right direction, it's still not working. Now it just repeats this step: else if (on == FALSE) { cup_on(); on == TRUE; cupon == TRUE; } Over and over again Edit: To clarify, when I say "over and over" I mean, when i hit the HUD button again it repeats, not that it's repeating on its own after one message from the HUD Edited February 1, 2021 by Ultea Link to comment Share on other sites More sharing options...
Fritigern Gothly Posted February 1, 2021 Share Posted February 1, 2021 2 minutes ago, Ultea said: Thank you! I knew I missed something obvious. But while that changed the behavior in the right direction, it's still not working. Now it just repeats this step: else if (on == FALSE) { cup_on(); on == TRUE; cupon == TRUE; } Over and over again Remember "==" compares two values. "=" assigns them. So you will have to at least make the following changes: on = TRUE; cupon = TRUE; Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 1, 2021 Share Posted February 1, 2021 3 minutes ago, Ultea said: else if (on == FALSE) { cup_on(); on == TRUE; cupon == TRUE; When you want to compare two things to see if they're equal, you need to use == as you did in the if-condition. When you want to set (assign) a value, you need to use =. You changed too much, you don't want those two last lines to be comparisons. Link to comment Share on other sites More sharing options...
Ultea Posted February 1, 2021 Author Share Posted February 1, 2021 Thanks everyone, that did the trick! Forgetting that, I wonder how I ever got it right in the first place. Link to comment Share on other sites More sharing options...
Fritigern Gothly Posted February 1, 2021 Share Posted February 1, 2021 (edited) Another tip is to replace the first 4 lines with all_off(); because it does the exact same thing and keeps your code short and easier to read. Edited February 1, 2021 by Fritigern Gothly Link to comment Share on other sites More sharing options...
Ultea Posted February 1, 2021 Author Share Posted February 1, 2021 Yes thank you, I was adding more lines just to be extra sure things were working right; originally I didn't have any of those statements written out, and will just use all_off/power_on/power_off again from now on! Link to comment Share on other sites More sharing options...
Kyrah Abattoir Posted February 1, 2021 Share Posted February 1, 2021 Pro tip, there is an interesting little pattern you can use for flip flop systems: on = !on; Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now