inexplicable behavior with switchables

shadowphile
24 Jun 2013, 01:17
I put a flashlight inside a clear jar and close it up. I can still switch the flashlight off and on! If the jar isn't clear, then I can't. And I can't find a way to intercept a switch verb before it occurs so I can slip in a ContainsReachable function.
I tried digging in to the default code for 'turnon' command to fix it there but I can't find anything resembling a script, not sure if object.switching is done below the ASL level. Anyone?

Pertex
24 Jun 2013, 09:38
This time you have to import the object type 'switchable'. There you can change the functions turnon and turnoff like this:

   <turnon type="script">
found = false
foreach (obj, ScopeReachable()){
if (obj = this){
found = true
}
}
if (found){
if (this.switchedon) {
msg (DynamicTemplate("AlreadySwitchedOn", this))
}
else {
if (HasString(this, "switchonmsg")) {
msg (this.switchonmsg)
}
else {
msg (DynamicTemplate("SwitchedOn", this))
}
this.switchedon = true
}
} else {
msg(DynamicTemplate("DefaultTurnOn", this))
}
</turnon>
<turnoff type="script">
found = false
foreach (obj, ScopeReachable()){
if (obj = this){
found = true
}
}
if (found){
if (not this.switchedon) {
msg (DynamicTemplate("AlreadySwitchedOff", this))
}
else {
if (HasString(this, "switchoffmsg")) {
msg (this.switchoffmsg)
}
else {
msg (DynamicTemplate("SwitchedOff", this))
}
this.switchedon = false
}
} else {
msg(DynamicTemplate("DefaultTurnOff", this))
}
</turnoff>


Could you test this code and tell me if it is working? Thanx

shadowphile
24 Jun 2013, 22:04
Thanks Pertex. Can you clarify the steps for me? I can't figure out what you mean. Import as in edit an aslx file directly? Which one? Or do you mean expose the switchable object type in the editor and modify that? I did the later, can't find anything referring to turnon or turnoff functions. :( I tried the former, sort of, but I can't figure out where.
Thanks again, nice to know it's not locked up in C# or something :)

edit: of course, right after my post I figured it out. That line this.lightstrength = "strong" in the original script was the key, guess I didn't look far enough! (haven't explored the object-type list much except to mess with default object stuff.

Liam315
24 Jun 2013, 22:29
You can just import it in the editor:

First click on Filter and then Show Library Elements

Expand the object tree to find:
Advanced>Object Types>Switchable

Copy switchable and in the attributes list are two separate attributes, one for turnon and another for turnoff.

Copy and past all the code between <turnon type="script"> and </turnon> into the turnon attribute (overwriting what's there) and then the same with turnoff.

shadowphile
24 Jun 2013, 22:37
thank you Liam and Pertex. The suggested script works. But even better, I'm now aware of another layer to investigate for questions such as these.