Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Confusion about LSL

VanMuur Spearmann
Registered User
Join date: 3 May 2006
Posts: 1
05-03-2006 06:43
Hey everyone,

I'm a relatively new LSL scripter, but pretty seasoned perl/python/ruby scripter (plus some other scripting languages). I'm a little confused about a few things:

1. Why can't I have functions inside a state? What if I want to polymorphize a state's particular function, so the same function can be called in each state, with different results? The state doesn't seemed to get passed with a function call, and therefore, when I call a function outside of a state, there's no particular way to get the function to react depending on state. (I've scoured the LSL Wiki for such examples, and can't find any.)

2. There are no such things as function pointers in LSL or function dispatching, is there? I'm attempting to call a function based on the contents of a string, and can find no way to do so. I.E. if a string variable contains "blah", then I want the function blah() called. Or, if the variable has "functionThree", then functionThree() gets called.

Any ideas on either?

Thanks,

VanMuur Spearmann
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
ahh
05-03-2006 06:55
Your seeing LSL as a fully functioning programming language.. It's not. It's a basic scripting language.

Wait till you try to find some error handling LOLOL.. We don't have any, and now they've made it so the errors have this dorky little white page popup if you get one, or you get a true popup window, your choice.
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
05-03-2006 09:33
I usually handle (1) by having a global which holds the 'current' state (I update it in each state's entry event handler), shared functions can then use this global to take state-dependent actions. For (2), I would just use an if-else construct.

In my experience, the limited size of LSL scripts means that you will quite quickly find yourself removing any 'best practice' structure or mechanisms that you try to include, in a desperate attempt to free up enough space even to fit in your basic additions and multiplications :)
Androclese Antonelli
Org. B-Day: 05/11/04
Join date: 25 Apr 2006
Posts: 96
05-03-2006 10:03
Jigsaw,

I'm running into that now. My thought is to break everything up into functions and make each function a separate script, then call them as needed.

Not having a lot of luck there yet... any ideas on how to make that work?
_____________________
The Sculpted Garden

Originally Born 5/11/2004 - New AV, Old Player.

If you leave the game, don't delete your account, just make it 'free'. You'll lose your inventory like I did. *sniff*
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
05-03-2006 11:28
Again, speaking just from my experience, the latency associated with link messages between scripts makes them unsuitable for as a direct replacement for 'method invocation', so you will always be running into major performance issues if you try that approach. They work quite well, however, if you treat them as a sort of RPC over a low-bandwidth network.

I am afraid most scripters eventually bite the bullet with LSL, and revert to coding as if they were working in assembler on an old DOS machine. Be mean with your instruction bytes, and your storage bytes, avoid string or list operations wherever possible, and put as much as possible into globals to avoid argument-passing overhead. Pack as much as possible into a single 'address segment' (i.e. script) as you can, and pray that no-one ever sees your source code.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
05-03-2006 11:37
Nice fancy high level features you will not find in LSL for one reason: You don't have the memory for them. Each script has 16k of memory. In that memory space, the scripts bytecode, stack and heap must all fit. LSL only has two types of pointers, string & list (keys are strings). The compexity of higher level features would eat all your memory.

As to state functions & state variables, there isn't a good reason why not.
BTW LSL doesn't use an optimizing compiler.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey