Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Can a UDF run from Dataserver?

Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-25-2008 03:13
Hi!

I've created a script to allow a parcel music url to be changed using menu buttons. Initially I created a list to check that the detected AV was an approved user. The AV checking code is stored in a user defined function. All works well at this point.

I decided it would be better to maintain a list of approved users on a notecard, and set up dataserver to read AV names on rows of a notecard. I can get a positive check that the AV detected is on the notecard, but it won't trigger my AV checking code in the user defined function that eventually puts up a menu (or not).

Can I not run a UDF from dataserver? Am I going about this in the wrong way? I haven't posted my code at this point, because I think it may be a design concept issue?

Any help appreciated!

Toby
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
04-25-2008 03:36
Are you reading the notecard, when a user clicks on the object?

If so, I'd recommend reading the notecard when it's changed, store the allowed AVs in a List and compare the clicking AV with the contents of this list.

Reading a notecard's contents takes some time and I guess it's quite slow that way.

Actually, you should be able to call UDFs from wherever you want to. Doesn't matter whether it's within a dataserver-event or somewhere else.
So there must be some other stuff going on. Posting your code might be helpful :)
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-25-2008 03:58
Thanks for your quick response Haruki.

Based on the time it takes to retrieve data from a notecard, I think I'll go back to using a list.

Cheers!

Toby
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
04-25-2008 04:16
Toby,

Using a notecard has the advantage, that it's easier to track the contents. It's not meant as a substitute for lists. What you do is read the notecard, and then store its contents in a list. Right now, I guess, you're filling the list with the AVs with chat-commands. So if you have quite a lot AV-names to add, it might be easier to put them in a notecard and have its contents read into the list.
Also, you don't have to bother when you want to remove an AV from the list. Just delete it from the notecard and then read the notecard again.
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-25-2008 04:24
Presumably I'd do that in State_Entry?

Toby
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
04-25-2008 04:45
You could do it in the state_entry(), yes...

But I'd recommend adding a change-event as well, so you just have to save the notecard, the changed-event will be triggered and the notecard's-contents will be re-read (have a look here, to find out more about the changed-event: http://www.lslwiki.net/lslwiki/wakka.php?wakka=changed).

Don't forget to set the AVs list to empty, before you re-read the notecard, otherwise, the contents of the notecard would just be added to the list (list myList = []);

Cheers

H
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-25-2008 06:56
Thanks for the tip on the Changed event. That's working well.

I'm sure there is an obvious answer to this, but how do I append quote marks (";) to the items I read from the notecard, so they are in the correct format for a List?

Edited: Discovered I could store quote marks on the Notecard

Toby
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-27-2008 09:32
I'm running dataserver from the Changed event, but I've noticed that the results are unreliable. If there are 4 rows on my notecard, sometimes all 4 are returned, sometimes 1, sometimes none.

Could there be something in my code causing this unreliability?

Toby
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
04-27-2008 22:15
From: Toby Lancaster
I'm running dataserver from the Changed event, but I've noticed that the results are unreliable. If there are 4 rows on my notecard, sometimes all 4 are returned, sometimes 1, sometimes none.

Could there be something in my code causing this unreliability?

You can't run dataserver from the changed event, since dataserver is an event too (and events don't nest). So I'm not sure what you mean.

It's always possible that the system is running so slowly that your request for the notecard line times out before the result is returned. But I'd like to see your code to be sure it isn't something there.
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-29-2008 10:58
OK I've simplified the code as follows:

CODE

list Access = [];
string name;
string gName = "Notecard1";//Name of Access list notecard
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries
default
{
changed(integer change) {
if (change & CHANGED_INVENTORY){

Access = [];
gName = llGetInventoryName(INVENTORY_NOTECARD, 0); // select the first notecard in the object's inventory
gQueryID = llGetNotecardLine(gName, gLine); // request first line
}
}
dataserver(key query_id, string data) {
if (query_id == gQueryID) {
llSay(0,"Rebuilding Access List");
if (data != EOF) { // not at the end of the notecard
//llSay(0, (string)gLine+": "+data); // output the line
Access = Access + (string)data + ",";
llSay(0,(string)Access);
++gLine; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request next line

}
}
}
}


If I add an entry to the Notecard, the list gets rebuilt (usually!), but if I remove a row, only a few, or one, or sometimes none of the rows on the notecard are read. Could it be due to lag, or something else?

Also, I've noticed that I don't seem to need to put the entries on my Notecard in quotes. Could that cause a problem?
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
04-29-2008 11:10
Dunno if this is _the_ problem but _a_ problem is that you don't reset gLine back to 0 when you start reading the notecard..

edit: also, if this object has more than just the script & notecard, you might want to remember the key of the notecard and check that in the changed event. If they key didn't change, it wasn't a change to the notecard that kicked changed.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
04-29-2008 11:30
In addition to what Meade said, you never actually use the initialized value of gName. This won't break things, and the memory usage is negligible, but it could be confusing in the future. Either insist on the notecard having a specific name, or don't initialize it.

Aside: For debugging purposes, I suggest getting into the habit of using llOwnerSay instead of lSay. If you ever have to test a script at a public place, it's courteous to avoid clogging public chat.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
04-29-2008 12:06
From: Kidd Krasner
Aside: For debugging purposes, I suggest getting into the habit of using llOwnerSay instead of lSay. If you ever have to test a script at a public place, it's courteous to avoid clogging public chat.

Seconded.

Actually, at the top of almost all scripts I write is something like this..

CODE

Say(string text)
{
llOwnerSay (text);
}


...which enables me to be a little lazy and not annoy people in chat range.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-29-2008 12:16
Thanks guys!

I think I have assigned gName in my proper script...just omitted from this abbreviated version.

I think reassigning gLine is a good spot. I'll try that next. Good tip on llOwnerSay too!

Toby
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-29-2008 23:44
Resetting gLine worked a treat.

Thanks for your help guys!

Toby
Toby Lancaster
Registered User
Join date: 28 Feb 2007
Posts: 14
04-30-2008 05:29
This script is actually used to set the music url on a parcel using an access list. So far, it's working fine.

I'd like to take this one stage further, and also have a linked prim which can change the music url on another parcel. I think I can figure how to pass the details to a script in a linked prim, but what sort of event could I use to trigger the linked prim to change the music url?

Both prims should change the url at the same time. In other words, I can trigger an event in the master prim, but I want that to cause a script in the child prim to run.

Toby
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
04-30-2008 07:50
All you need is a listen event. Have the main radio llSay() or llRegionSay() the URL and have the slave script call llSetParcelMusicURL() in the listen event. use a large negative channel to avoid accidental trigering and if you realy need to be secure you can test the key of the calling object.