| Scripting Discuss scripting and programming for SL and other platforms |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) | |
| Senior Member ![]() ![]() ![]()
penguins rule!
Join Date: Jan 2012
Posts: 1,364
My Mood: SL Join Date: 5/30/2011 Client: Firestorm | 1 script or 2? I have a project that I'm working where if a J Random avatar clicks on it, it hands them a LM. But if the owner clicks on it it tosses up a control menu. From a simplicity point of view it would be simpler to break this up into 2 scripts. One for the LM giver and another script for the control menu. A more complex script could do both but would be harder to maintain. A single script would also be better on sim resources.
__________________ Quote:
| |
| | |
| |
| | #2 (permalink) |
| The Purple ![]() ![]() ![]() ![]() ![]() ![]()
HEYOO!
Join Date: Dec 2007 Location: Somewhere purple, Germany
Posts: 7,648
My Mood: SL Join Date: 20. January 2007 Client: NaCl | No. That's so utterly simple, breaking that into two scripts pretty much equals breaking into scripts every time an if() statement could be used. Code: integer iListener;
key kOwner;
default
{
state_entry()
{
kOwner=llGetOwner();
}
on_rez(integer foo)
{
llResetScript();
}
touch_start(integer foo)
{
if(llDetectedKey(0) == kOwner)
{
iListener=llListen(12345,"",kOwner,"");
llSetTimerEvent(10);
//domenuhere on channel 12345
}
else
{
//Else give landmark <- Don't break up the script because of this.
}
}
timer()
{
llListenRemove(iListener);
llOwnerSay("Menu timed out!");
}
listen(integer channel, string name, key id, string message)
{
//Handle menu replies, possibly restart timer to wait for new button clicks.
}
changed(integer change)
{
if(change & CHANGED_OWNER)
llResetScript();
}
}
__________________ "Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?" - George Carlin Last edited by Chalice Yao; 07-17-2012 at 12:31 PM. |
| | |
| 1 User Hugged You: |
| 1 User Said Thanks: |
| 2 Users Like This: |
| | #3 (permalink) | |
| Senior Member ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Posts: 6,081
| Quote:
I really meet the most interesting people. | |
| | |
| 3 Users Laughed: |
| 2 Users Hugged You: |
| | #4 (permalink) |
| Senior Member ![]() ![]() ![]()
penguins rule!
Join Date: Jan 2012
Posts: 1,364
My Mood: SL Join Date: 5/30/2011 Client: Firestorm | Oh I see. That is simpler that what I was planning to do. I was planning something with states. One state for owner and one state for everyone else. Thanks. Now I'm wondering why I didn't think of that. |
| | |
| | #5 (permalink) | |
| The Purple ![]() ![]() ![]() ![]() ![]() ![]()
HEYOO!
Join Date: Dec 2007 Location: Somewhere purple, Germany
Posts: 7,648
My Mood: SL Join Date: 20. January 2007 Client: NaCl | Quote:
I can't remember the last time I used states. But that's personal preference. Usually I just use if()s for stuff like that. Changing states only makes sense if you really wish to radically change the entire behavior of the object, IMO. | |
| | |
| 1 User Agreed: |
| | #6 (permalink) | |
| Senior Member ![]() ![]() ![]()
penguins rule!
Join Date: Jan 2012
Posts: 1,364
My Mood: SL Join Date: 5/30/2011 Client: Firestorm | Quote:
| |
| | |
| | #7 (permalink) | |
| Senior Member ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Posts: 6,081
| Quote:
But yeah. As a general rule, it's best to avoid breaking code into multiple scripts unless it's an absolute must due to some LSL shortcoming or a set/get link function that should exist but doesn't yet. (there's a few remaining) | |
| | |
| 1 User Said Thanks: |
| | #8 (permalink) | ||
| That Bitch ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() *SLU Supporter* ![]() ![]() ![]() ![]() ![]()
Innocent as far as you know
Join Date: Nov 2011 Location: Online
Posts: 6,195
My Mood: SL Join Date: late 04... that account is deleted now | as a further note, states aren't really such a great thing to use in LSL... they seem like it, but they're really special purpose. the only time they really are useful is to limit/change what input events (rather than how they act) are available, and the side benefit of dropping all open listens... they have drawbacks like dropping queued events, and taking longer to set up though. for behavior changes on the input, simpler and more efficient to just use flags or tests. it will probably help if you think of events in an object oriented manner of handlers for specific inputs, and treat states optional switches for the kinds of input you are willing to accept. @Adeon: You really DO meet "interesting" people o.O (and I would've thought troll too!) about the only time I'll avoid using a test is if it makes me duplicate the same code, in which case I'll try to do it with a flag and inline math if possible. ETA: might want to avoid storing owner key for the check as in Chalice's example... if you check directly against the llGetOwner the performance loss isn't significant and you no longer need to reset or update it when the owner changes... I'd only use the variable if there's a need to reset on owner change or you find yourself needing that owner key to use a whole lot. but that's a style difference
__________________ - These eyes can do more than see Quote:
Quote:
Last edited by Void; 07-17-2012 at 01:47 PM. | ||
| | |
| 2 Users Agreed: |
| | #9 (permalink) | |
| The Purple ![]() ![]() ![]() ![]() ![]() ![]()
HEYOO!
Join Date: Dec 2007 Location: Somewhere purple, Germany
Posts: 7,648
My Mood: SL Join Date: 20. January 2007 Client: NaCl | Quote:
| |
| | |
| | #10 (permalink) |
| Senior Member ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Posts: 6,081
| Hm, I use states in my light switch examples. Having only two touch_start's, one in each state, each sending the code to the other, seemed to get people started quicker before learning global variables. And simple light switches/toggles seem to always get requested. |
| | |
| | #11 (permalink) | |
| The Purple ![]() ![]() ![]() ![]() ![]() ![]()
HEYOO!
Join Date: Dec 2007 Location: Somewhere purple, Germany
Posts: 7,648
My Mood: SL Join Date: 20. January 2007 Client: NaCl | Quote:
| |
| | |
| | #12 (permalink) |
| That Bitch ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() *SLU Supporter* ![]() ![]() ![]() ![]() ![]()
Innocent as far as you know
Join Date: Nov 2011 Location: Online
Posts: 6,195
My Mood: SL Join Date: late 04... that account is deleted now | heh I actually use the opposite approach there and use a global flag to get them more comfortable with the idea of boolean switches... once they're comfortable with those it's so much easier to explain bitwise operators and bit masks (although then the hurdle becomes teaching the relation between bitwise operations and integer math, but hey one step at a time right?) |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |
| |