Difference between revisions of "User:Kira Komarov/Trick or Treat"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "=Tricks for Developers= There are a number of problems that I got around while writing this script. # '''There is no way to get the amount of L$ your avatar has on itself.''' …")
 
m
Line 3: Line 3:
There are a number of problems that I got around while writing this script.
There are a number of problems that I got around while writing this script.


# '''There is no way to get the amount of L$ your avatar has on itself.'''
* '''There is no way to get the amount of L$ your avatar has on itself.'''


One way around that, is to pay an amount into an object and count the money using money(). Not only will the script now be aware of the money, but you can thereby implicitly set a limit. Neat!
One way around that, is to pay an amount into an object and count the money using money(). Not only will the script now be aware of the money, but you can thereby implicitly set a limit. Neat!


# '''Dang! I already used up the timer() event.'''
* '''Dang! I already used up the timer() event.'''


Use llSensorRepeat() with some ridiculous parameters (initially I was searching for Philip Linden's key in a 0.1 range) and a repeat time of your desired time. Since the llSensorRepeat() is crafted to fail and trigger no_sensor() all the time it runs, you can use no_sensor() as your timer() equivalent. In fact with llSensorRemove() you can have your llSetTimerEvent(0) call.
Use llSensorRepeat() with some ridiculous parameters (initially I was searching for Philip Linden's key in a 0.1 range) and a repeat time of your desired time. Since the llSensorRepeat() is crafted to fail and trigger no_sensor() all the time it runs, you can use no_sensor() as your timer() equivalent. In fact with llSensorRemove() you can have your llSetTimerEvent(0) call.
Line 20: Line 20:
Now you have freed up the timer() event, effectively having two timers. Neat!
Now you have freed up the timer() event, effectively having two timers. Neat!


# '''Heap protection. Adding and adding stuff to lists will eventually make the stack collide with the heap.'''
* '''Heap protection. Adding and adding stuff to lists will eventually make the stack collide with the heap.'''


Ideally, you could measure the amount of free memory and flush those lists when it becomes critically low. Since we are unable to do that reliably, you can just flush them after a certain period of time and size. For example, this script will check every 60 seconds if the DONORS and RETRIEVERS lists are over 25 elements and flush them if they are.
Ideally, you could measure the amount of free memory and flush those lists when it becomes critically low. Since we are unable to do that reliably, you can just flush them after a certain period of time and size. For example, this script will check every 60 seconds if the DONORS and RETRIEVERS lists are over 25 elements and flush them if they are.


This should be kept in mind for logging scripts which continuously add to the heap. Eventually, if there is no upper limit on the data, the script will crash.
This should be kept in mind for logging scripts which continuously add to the heap. Eventually, if there is no upper limit on the data, the script will crash.

Revision as of 20:06, 18 November 2011

Tricks for Developers

There are a number of problems that I got around while writing this script.

  • There is no way to get the amount of L$ your avatar has on itself.

One way around that, is to pay an amount into an object and count the money using money(). Not only will the script now be aware of the money, but you can thereby implicitly set a limit. Neat!

  • Dang! I already used up the timer() event.

Use llSensorRepeat() with some ridiculous parameters (initially I was searching for Philip Linden's key in a 0.1 range) and a repeat time of your desired time. Since the llSensorRepeat() is crafted to fail and trigger no_sensor() all the time it runs, you can use no_sensor() as your timer() equivalent. In fact with llSensorRemove() you can have your llSetTimerEvent(0) call.

Here is a pragmatic equivalence table (NUMBER is the number of seconds, replace with a value):

llSetTimerEvent(NUMBER) <=> llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, NUMBER)
timer() <=> no_sensor()
llSetTimerEvent(0) <=> llSensorRemove()

Now you have freed up the timer() event, effectively having two timers. Neat!

  • Heap protection. Adding and adding stuff to lists will eventually make the stack collide with the heap.

Ideally, you could measure the amount of free memory and flush those lists when it becomes critically low. Since we are unable to do that reliably, you can just flush them after a certain period of time and size. For example, this script will check every 60 seconds if the DONORS and RETRIEVERS lists are over 25 elements and flush them if they are.

This should be kept in mind for logging scripts which continuously add to the heap. Eventually, if there is no upper limit on the data, the script will crash.