• All submissions to this site are governed by Second Life Project Contribution Agreement. By submitting patches and other information using this site, you acknowledge that you have read, understood, and agreed to those terms.
Issue Details (XML | Word | Printable)

Key: SVC-3297
Type: New Feature New Feature
Status: Open Open
Priority: Nice to have Nice to have
Assignee: Unassigned
Reporter: Cinco Pizzicato
Votes: 13
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
2. Second Life Service - SVC

LSL - Allow for state-scope variables

Created: 23/Oct/08 12:51 PM   Updated: 27/Jul/09 03:43 PM
Return to search
Component/s: Scripts
Affects Version/s: None
Fix Version/s: None

Environment: n/a
Issue Links:
Relates
 


 Description  « Hide
I'm writing a lot of code that makes http requests, which means each request gets its own state (make the request on state_entry, gather the data in http_response, figure out which data is needed next, go to the state for that data, or timeout in timer event). This means that not only do I have to share data between states using globals, but also that data which should be specific to that state has to be global as well. This leads to a lot of silly naming conventions and trying to remember which global goes with which state, as well as a lot of time wasted scrolling up and down to see the variables. And, of course, a bunch of memory being eaten by variables that only see the light of day within one state.

So I propose declaring the variable after the state declaration and before the first event. A state-scope variable: Any event in the state can use these variables, but they disappear once you leave the state. This would increase readability and reuseability. Pseudocode follows:

state httpFetch
{
    key httpID;
    float httpTimeout = 30.0;
    state_entry()
    {
        llSetTimerEvent(httpTimeout);
        httpID = llHTTPRequest("http://yeah.right/", [etc]);
    }
    
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id==httpID)
        {
            etc.....
        }
    }
}


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Maggie Darwin added a comment - 24/Oct/08 05:48 AM
Excellent idea. Voted.

Strife Onizuka added a comment - 24/Oct/08 01:06 PM
I haven't seen this suggested in years. It wouldn't be hard to implement in LSO or in Mono (only requires changes to the compiler, no VM changes needed). Mind you for LSO, you would need to insert code into the start of the state_entry() event (and insert a state_entry() event too if needed).

In LSO you would implement it with globals and recycle the memory addressed depending upon the state.
In Mono it would be much easier.


Cinco Pizzicato added a comment - 24/Oct/08 02:54 PM
Thanks for the code tags, Strife. One of these days I'll have to learn Jira Markup Language.

A state that declared a variable but had no events would be a no-op anyway, and one would hope the compiler would ignore the variable declaration when it came to allocating memory.


Strife Onizuka added a comment - 24/Oct/08 04:33 PM
The compiler isn't that smart sadly... BUT I don't think it will currently let you declare a state without atleast one event.