Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripts that only need to run once

Randwulf Xue
Registered User
Join date: 13 Nov 2008
Posts: 1
02-27-2009 19:34
Currently the object I'm working on has two scripts. The first one, when rezzed, checks (using an HTTP request) if the owner of the object has rezzed it before or not. If they have not, if it's their first time rezzing the object, then the script shuts itself off with llSetScriptState FALSE and starts the other script with llSetScriptState TRUE.

I have it do this because the second script only needs to be run once and I don't want to clog the first script's memory with useless code. Is there a better way of achieving what I want? It behaves unpredictably as it is now. Sometimes it works, other times it just does nothing.

And is there a way for a script to be OFF by default when the object is rezzed?

Thanks.
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
02-27-2009 21:44
Yep. Just go to the script edit window and uncheck "Running."
_____________________
Life is a highway... And I just missed my exit.
Lennard Lopez
Registered User
Join date: 9 Oct 2007
Posts: 52
02-27-2009 23:49
Hi Randwulf.

Better to use:
llSetScriptState(llGetScriptName(),FALSE); //Script stops running

In the other script you could use in on_rez or state_entry:
llSetScriptState(<one time script name>,TRUE); //continue running
llResetOtherScript(<one time script name>;); //reset the script so it starts at the begin
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
02-28-2009 01:01
For that matter, how about llRemoveInventory(llGetScriptName())

Script is deleted, so it can't run again.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-28-2009 09:42
presumably the first script needs to resume running after the second script runs on the first go through?

first script runs, finds first time rezzed indication, moves to a wait state and triggers the second script.
second script runs which presumably updates the first rez info, fires off a message that it's done (then either shuts itself off, or self deletes)
first script receives message from second script, and either resets itself, or just moves on to another state (like the default with an on_rez handler?)

just uncheck running, but also remember that scripts that are turned off while running restart in the same place (do may need to be reset). and I don't believe that a script that is woken up will catch certain events (like on_rez) so be aware
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-28-2009 09:50
Is the script or object no-transfer? If not, you may not want to shut it off because then it will never run again, even when transferred to another owner. Instead, you might just want to have it do its thing on a 'changed' event where the 'CHANGED_OWNER' flag is true in the event flags.

I'm also not sure why you have two scripts, one of which just tells the other to do something once. Why not just include the run-once logic in the second script? If you're really interested in saving server time, you're certainly not doing any good by adding another (essentially) do-nothing script. (I'm not saying there wouldn't be valid reasons for doing this, but saving server cycles certainly isn't one of them.)
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-28-2009 16:19
From: Hewee Zetkin
Is the script or object no-transfer? If not, you may not want to shut it off because then it will never run again, even when transferred to another owner. Instead, you might just want to have it do its thing on a 'changed' event where the 'CHANGED_OWNER' flag is true in the event flags.

I'm also not sure why you have two scripts, one of which just tells the other to do something once. Why not just include the run-once logic in the second script? If you're really interested in saving server time, you're certainly not doing any good by adding another (essentially) do-nothing script. (I'm not saying there wouldn't be valid reasons for doing this, but saving server cycles certainly isn't one of them.)


I'm guessing the script that needs to run all the time is either maxed, or nearly maxed out on memory usage, or uses lists and needs a lot of memory available. and the user wanted to do something that only happens once per use in a separate script so it doesn't eat up memory that the other script needs. as far as needing it to run only once per user, i would assume it is transferable. but if the script that runs the http request is turned off, how does it know to do the request when it changes owners?
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
02-28-2009 21:59
I'd probably use llGetOwner(), which returns the previous owner until the script is reset, even if the item is transfered. That way, when the object is given away or sold, the previous owner's name will be returned when llGetOwner() is called. You can store the initial creator's key (your key) in the description area, and compare it to llGetOwner(). If they're different, you can assume that the item has transferred, and, at that point, perform your once only stuff, including putting the new owner's key into the description, then reset the script which will make the script see the current owner as the new owner. This would also make the 'run once' stuff work again should the object be transferred to yet a new owner (item is given away or sold off).
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-28-2009 22:18
Actually llGetOwner() always returns the CURRENT owner. To remember the "last" owner, store the key in a global variable. No script resets necessary. And if you don't really need to know WHO the previous owner was, the 'changed' event will TELL you every time there is a (detectable) change in ownership by passing a parameter to the handler that has the CHANGED_OWNER flag set. Shouldn't even really need the global variable unless you really want to be paranoid about it or need for some reason to do something with the identity of the previous owner. Definitely don't need to use the prim description field for this simple an application.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=changed
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetOwner
Lily Cicerone
Registered User
Join date: 25 Jan 2007
Posts: 30
02-28-2009 22:31
I'm not completely sure what this script is doing, but honestly, the amount of memory consumed by a state that does nothing but check whether the script has run is negligible. I would just not worry about it -- Mono tends to perform better when you keep things in as few scripts as is reasonable anyway.