Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dynamically creating a new notecard using LSL

Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 06:40
Quick googling told me it can't be done, but I am wondering if there is a way? Could i, for example, create a new card from querying a website and putting retun of HTTPRequest into it? Or just have some function like llNewNoteCard( string text )?
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-20-2009 06:45
Nope.

Aside from rezzing things in the objects inventory, scripts cannot create or modify assets. You'd need a bot to do it.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 07:23
From: Sindy Tsure
Nope.

Aside from rezzing things in the objects inventory, scripts cannot create or modify assets. You'd need a bot to do it.


I see.

The problem I was working on, is that a bunch of objects in the project I am working on will give the same notecard, but they all contain their own copy, so its a bitch to go and modify each one each time the text of notecard changes. What I think I will do, is designate one object as notecard holder, and other object can send requests to it via chat channel with avatar's key, and the notecard prim can give the notecard to whichever key was sent to it via chat.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 07:41
on a related note, is it possible to dynamically create a new LSL script and run it?

The reason for this, is because maybe in the future I may want to createa compiler compiler for some language that would output code in LSL.

So, for example, I would be able to send BNF + LSL code for actions to some webserver and have it return LSL that should be put in its own script and run.

Is this at all possible?
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-20-2009 07:47
Nope - you can't really create anything dynamically via a script. Think about how much fun griefers would have if they allowed it!

Spot on with having one object hold the notecards and others just being slaves to that.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 10:14
ok here is what I came up with. If you guys want to, move it to the script library forum, maybe it could be useful for someone:

Client Script. Put this inside object that avatars will click on to get their notecard:
CODE

integer note_card_channel = 10012;

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_end(integer total_number)
{
llShout(note_card_channel, (string)llDetectedKey(0));
}
}


server script. Create one object that contains the notecard you want to give, and put this script inside of it
CODE

integer note_card_channel = 10012;

give_note_card( key av_key )
{
llGiveInventory( av_key,llGetInventoryName(INVENTORY_NOTECARD, 0));
}

default
{
state_entry()
{
llListen( note_card_channel, "", "", "" );
}

listen(integer chan, string name, key id, string msg )
{
give_note_card( (key)msg);
}
}
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-20-2009 10:30
Good start but I have a couple suggestions...

You could have the server rez you a giver when you touch it. That would allow you to have the server use a random channel, which is probably what you want if you're going to have multiple servers within a sim.

You can use llRegionSay instead of llShout. In theory, it's more efficient and you don't run into the 100m shout limit.

Hello, Avatar!

Using negative channel numbers is done more often for scripts that talk to each other. That prevents them from picking up on chat - users can't speak on channels <0.

You should have the servers listen event only send the notecard if llGetOwnerKey(id) == llGetOwner(). That will prevent people from using your script to spam others and prevent crosstalk with other people who have the same script, if you don't do the random channel thing..
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 10:39
From: Sindy Tsure
Good start but I have a couple suggestions...

You could have the server rez you a giver when you touch it. That would allow you to have the server use a random channel, which is probably what you want if you're going to have multiple servers within a sim.

You can use llRegionSay instead of llShout. In theory, it's more efficient and you don't run into the 100m shout limit.

Hello, Avatar!

Using negative channel numbers is done more often for scripts that talk to each other. That prevents them from picking up on chat - users can't speak on channels <0.

You should have the servers listen event only send the notecard if llGetOwnerKey(id) == llGetOwner(). That will prevent people from using your script to spam others and prevent crosstalk with other people who have the same script, if you don't do the random channel thing..


sweet, thank you a lot, that is very helpful.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-20-2009 18:46
Couple of other ideas.

If you are willing to use llHTTPRequest() already (since you asked about populating a notecard with the resuls), why not just skip the notecard? Keep the results of your HTTP request in script memory (in your main script or in a helper devoted to data storage and/or querying) and use new HTTP requests to pull bits not currently stored. All it changes is what function call you use to grab your data (llGetNotecardLine(), llHTTPRequest(), llMessageLinked()) and what event you receive the reply in (dataserver, http_response, link_message).

To fulfil the same goal you were looking for in trying to dynamically create scripts, you could make some kind of interpreter. A very simple language would be doable in LSL (maybe a simple version of Lisp even?), complex ones would be a more ambitious project. I doubt writing a full LSL interpreter would be worth it (and it would certainly take more than a single script; probably more like a whole system of interworking scripts). Or, you could possibly have a script of some sort running on a remote server, communicate with it over HTTP, and have it use the script for its input/output terminal.