Jump to content

A non-scripter combining scripts...OMG!!!


Oddball Otoole
 Share

You are about to reply to a thread that has been inactive for 4797 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello!

As said in the subject of this message, I'm a non (very non)-scripter. But willing to learn:) 
I'm trying to combine some scripts (a menu driven script that gives folks who touch a prims, a menu with two (2) choices: Receive a notecard from prims inventory, and option #2: open a website).

I made this:

// Basic dialog script

integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["Notecard", "Website"]; // the main menu

default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
       // llSetText("Dialog Test",<1,1,1>,1.0);
    }
    touch_start(integer total_number)
    {
        llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
    }
    listen(integer channel, string name, key id, string message)
    {
        if (message == "Notecard")
        {
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_NOTECARD, 0));
        }
        else if (message == "Website")
        {
llLoadURL(llDetectedKey(0), "Oddballs Second Life Forum", "http://www.oddball.be"); 
        }
        else if (message == "...Back")
        {
            llDialog(id, "Select option", MENU_MAIN, CHANNEL); // present main menu on request to go back
        }       
    }
}

 It compiles ok, no script errors, if I touch the prim, a menu appears (YAY), then things go wrong....

If I click on the 'Notecard' button, nothing happens.
If I click on the 'Website' button, I receive a script error: Object: llLoadURL - cannot find avatar.

What am I doing wrong here?

Greetz,
Oddy 

 

Link to comment
Share on other sites

llDetected* commands only work from events that do detection... listen isn't one of those, instead replace those calls within the listen with the "id" variable, that will contain the same information.

PS

 

other minor things:

you check for "...Back" but it's not presented as an option in the dialog.

you can reduce typo errors for the dialog selection by checking if the response is in the list that you used to send the dialog. then use the index to decide which code to run... it also keeps you from maintaining strings in two places.

"" is actually preferable to NULL_KEY, and evaluates the same.

 

Link to comment
Share on other sites

Just to expand on what the others have said, what listen(integer channel, string name, key id, string message) means -- and I remember it took me a while to appreciate this -- is that channel, name, id and message are the names of variables, grabbed by the listen event, and available to the script in that event.   

So you can say something like:

 

default{	state_entry()	{		llListen(99,"","","");//listen on channel 99 for messages from anyone	}	listen(integer channel, string name, key id, string message)	{		llInstantMessage(id, "Hello, "+name+"! You said \""+message+"\" on channel "+(string)channel+ " and your uuid is "+(string)id);	}}

 

If you want to make variables available outside the particular event, you have to use global variables, which means declaring them before you enter state default in the script, as you have done with CHANNEL and MENU_MAIN in your example.   So something like this would work, too

// Basic dialog scriptinteger CHANNEL = 42; // dialog channellist MENU_MAIN = ["Notecard", "Website"]; // the main menukey toucher;default{	state_entry()	{		llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users) // llSetText("Dialog Test",<1,1,1>,1.0);	}	touch_start(integer total_number)	{		toucher = llDetectedKey(0); // give the variable "toucher" the value of the uuid of whoever's just touched me		llDialog(toucher, "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click	}	listen(integer channel, string name, key id, string message)	{		if (message == "Notecard")		{			llGiveInventory(toucher, llGetInventoryName(INVENTORY_NOTECARD, 0)); //the script knows what you mean by "toucher" in a new event		}		else if (message == "Website")		{			llLoadURL(toucher, "Oddballs Second Life Forum", "http://www.oddball.be");		}		else if (message == "...Back")		{			llDialog(toucher, "Select option", MENU_MAIN, CHANNEL); // present main menu on request to go back		}	}}

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4797 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...