Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

does LSL break the event driven model?

Codswallop Cassidy
Registered User
Join date: 30 Dec 2003
Posts: 53
09-12-2004 05:21
I'm asking this question because I'm not very familiar with event driven programming as a paradigm, and aside from experience with VB, I've just had OOP up the ass probably like many people here. However I ask because..

One reason, in one of my scripts I have the default, state_entry event read two notecards. The reading of each notecard is encapsulated in two functions so the code pretty much looks something like this.


Function1()
{
.....
key something = llGetNotecardLine(....);
}

Function2()
{
.....
key something = llGetNotecardLine(....);
}


default
{
state_entry()
{
........
Function1()
.......
Function2()
.....
}

dataserver(....)
{
// does the actual reading/parsing here
....
}

}


The problem is, both functions are called , but the first dataserver event doesn't even kick in until after state_entry() was finished. I ended rewriting the whole thing so that the first llGetNotecardLine is called in Function1, then the whole thing goes into dataserver and handles everything else from there. However my intention and understanding was that as soon as the program goes into Function1() and makes the LLGetNoteCardLine call, the dataserver event would be triggered and afterwards, control would return to the function, which would then exit and return to state_entry.

Obviously it didn't turn out that way which immediately had me starting to bitch, but also made me ask "Do I really know anything about event driven programming?" Probably not, considering I havent much experience with languages outside of VB (and even then not really that much).

So is this how it's supposed to work? or is there something funny going on here. It looks like an event can make a function call and then return control to an event, but a function call cannot then trigger another event until the event from which it was called is finished. Is this how it's supposed to be? dataserver in my case was meant to be an event I could call multiple times to just read notecards and stuff some things into lists :P
Siro Mfume
XD
Join date: 5 Aug 2004
Posts: 747
09-12-2004 05:43
From what I've seen of successfully implemented programs in LSL like you describe, events run simultaneously but as they are called. So essentially you're calling the data server event twice in rapid succession and further you expect it to operate instantaneously. This just is not to be.

What I've seen from working code is at the end of a data server event is that they enter another state. For calling two note cards, especially for initialization purposes, this would be very useful.

So more of something like this:


Function1()
{
.....
key something = llGetNotecardLine(....);
}

Function2()
{
.....
key something = llGetNotecardLine(....);
}


default
{
state_entry()
{
........
Function1()
.......
(other init relating to Function1())
}

dataserver(....)
{
// does the actual reading/parsing here
....
state Step2;

}

Step2
{
state_entry()
{
........
Function2()
.......
(other init relating to Function2())
}

dataserver(....)
{
// does the actual reading/parsing here
....
state Running;

}

Running
{
state_entry()
{
....
//now your object is all set up with info from two notecards and you're ready for touch events, money events, control events, change events, and anything else.
}

The point here is that dataserver is not a function, it's an event. What's more is it's slow. Typically you only read a notecard once since you can't write to them yet anyway.
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
09-12-2004 05:45
- each script is single-threaded
- only one event can run at a time
- events are queued as they arrive, and will run in turn once the current event is finished

What you need to do is make two global variables called Request1 and Request2, assign the result of your GetNotecardLine call to Request1 or Request2. In the dataserver event check the value of the key passed in against Request1 and Request2 to see which one it is the result of.

Welcome to the world of asynchronous function calls.
_____________________
Codswallop Cassidy
Registered User
Join date: 30 Dec 2003
Posts: 53
09-12-2004 14:21
Thanks for the feedback. Yup I was wondering about the distinction between an event and a function anyway, thanks.