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

From Second Life Wiki
Jump to navigation Jump to search
m
m
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
=Tricks or Treats for Programmers=
{{delete|Redundant now since the same content can be found under [[Wizardry and Steamworks]]}}
 
==[[The Stash (Bank)]]==
 
* '''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. However, you should keep in mind that different from llSetTimerEvent(), the llSensorRepeat() call immediately proceeds to scan which would make the no_sensor() event fire right away before it is rescheduled.
 
To get around that problem, just use some global variable that will make no_sensor() return just on the first entry. Something like this might be appropriate:
 
<lsl>
integer flag;
 
default
{
    state_entry() {
        flag = 1;
        llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, 60);
    }
    no_sensor() {
        if(flag) {          // <--- tests flag, which will be 1 for the first run and then brings it back to 0, making it fail on the next entry of no_sensor().
            --flag;
            return;
        }
        // this area will be hit 60 seconds after the llSensorRepeat() has been executed.
    }
}
</lsl>
 
Here is a equivalence table (NUMBER is the number of seconds, replace with a value):
<pre>
llSetTimerEvent(NUMBER) <=> llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0.1, NUMBER)
timer() <=> no_sensor()
llSetTimerEvent(0) <=> llSensorRemove()
</pre>
again, keeping in mind that llSensorRepeat() will immediately trigger no_sensor().
 
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.

Latest revision as of 00:30, 29 August 2012

Deletion Requested
The deletion of this article was requested for the following reason:

Redundant now since the same content can be found under Wizardry and Steamworks

If there is a need to discuss the deletion of this article, please add your comment(s) here.


@Admin: Please read the discussion before deleting the article.