Jump to content

Help with House Controller Scripts


Leander Tyles
 Share

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

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

Recommended Posts

Hi, im trying to make a HOUSE CONTROLLER, for (doors/windows/security) that kind of thing

but ive run into a problem with the radio script plugin

llDialog(id, "\npick a station", _radioStations, -1000);

^ this line doesnt work because ID is the object key from the second snippet of code.... not an avatar so i dont recieve the dialog.

 

after i fix that problem somehow, no doubt thier will be an issue with the listener...... im worried about what will happen when the radio script hears commands on -1000 which aint neccaserilly a request to change the station/url.

wanna avoid using even more listeners/channels  

 

 

// send infomation regarding person who can control it

    touch_start(integer total_number)
    {
       llSay(-1000,"security " +(string)llDetectedKey(0));
    }

 this is the main menu listening on channel 3

list buttons = ["Security","Radio","Textures","Cancel"];

integer secretchannel = -1000;
integer tenantchannel = 3;
key tenantkey = NULL_KEY;

integer listen_handle;

integer menu_handler; 
integer menu_channel;

list order_buttons(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}

default
{

    state_entry()
    {
        //llResetScript();
        listen_handle = llListen(secretchannel, "", "", "" );
    }
    
    on_rez(integer start_param) { llResetScript(); }

    listen(integer channel, string name, key id, string message)
    {
    // SETTING WHO CAN ACCESS
    if (channel == secretchannel && llGetOwnerKey(id) == llGetOwner()) {
     if (llGetSubString(message, 0, 7) == "security" && tenantkey == NULL_KEY)
        {
            tenantkey = llGetSubString(message, 9, -1);   
            llListenRemove(listen_handle);
            listen_handle = llListen(tenantchannel, "", tenantkey, "" );
            llSay(0,"Type /" +(string)tenantchannel+ "menu - for controls.");
        }
    }
    // TENANT CONTROLS
      else if (channel == tenantchannel && id == tenantkey) {
      if( llToLower(message) == "menu" )
            {
            llDialog(id,"\nPlease Choose a Button",order_buttons(buttons),tenantchannel);
            llSetTimerEvent(60);
            }
            if (message == "Cancel") { }
            if( llToLower(message) != "menu" && llToLower(message) != "cancel" ) 
            {
            llSay(secretchannel,"request:" +message);
}
}
}
}

 

 

 heres the problematic radio script plugin

list    _radioURLs;
list    _radioStations; 
integer _linenum = 0;
string  _notecard = "stations";

//-----------------------

reset_radio() {
    _radioURLs = [ "" ];
    _radioStations = [ "off" ]; 
     _linenum = 0;
    llGetNotecardLine(_notecard, _linenum);
}

add_station(string line) {
    list words = llParseString2List(line, [" ", " ", "="], []);
    if (llGetListLength(words) < 2) {
        return;
    }
    string url = llList2String(words, llGetListLength(words) - 1);
    string station = "";
    integer i;
    for (i=0; i<llGetListLength(words) - 1; i++) {
        if (llStringLength(station) > 0) {
            station += " ";
        }
        station += llList2String(words, i);
    }
    _radioURLs += [url];
    _radioStations += [station];
}

//-----------------------

default {
    state_entry() {
        reset_radio();
    }
    
    changed(integer change) {
        if (change & CHANGED_INVENTORY) {
            reset_radio();
        }
    }

    dataserver(key query_id, string data) {
        if (llGetListLength(_radioURLs) > 11) {
            llSay(0, "only the first 10 stations are avaliable");
        }
        else {
            if (data != EOF) {
                add_station(data);
                _linenum++;
                llGetNotecardLine(_notecard, _linenum);
                return;
            }
        }
        llListen(-1000, "", NULL_KEY, ""); 
        llSay(0, "touch to change stations");
    }

  listen(integer channel, string name, key id, string message) {
        if (message == "request:Radio") 
        {
        llDialog(id, "\npick a station", _radioStations, -1000);
        }
        else {
        string newURL = llList2String(_radioURLs, llListFindList(_radioStations, [message]));
        llSay(0, message + " ---> " + newURL);
        llSetParcelMusicURL(newURL);
    }
}
}

 

Link to comment
Share on other sites

The easy answer is not to get too paranoid about adding an extra listener.  Especially if it's listening on a unqiue high-numbered channel, the amount of added strain it puts on the sim's servers is truly negligible.  You already have a timeout on the dialog so that one isn't open for more than a minute.  Don't worry about it.  :smileywink:

Link to comment
Share on other sites

listen(integer channel, string name, key id, string message) {        if (channel == -1000 && message == "request:Radio")         {        llDialog(id, "\npick a station", _radioStations, -5430);        }        if (channel == -5430) {        string newURL = llList2String(_radioURLs, llListFindList(_radioStations, [message]));        llSay(0, message + " ---> " + newURL);        llSetParcelMusicURL(newURL);    }}}

 ok, but how i do solve the dialog problem

Link to comment
Share on other sites

Ok, here's the problem.  When you send the "request:Radio" message from the first script, the radio plugin script is receiving the key of the object the script is in, not the key of the person who touched the object.  The touch isn't passed to the radio plugin script, so you have to send the user's key and use it to get the dialog to pop up for the user.

Link to comment
Share on other sites

We're just handling the results of a dialog here. Either message is in the _radiostations list or it isn't. If it's not, ignore it, or fuss about getting unexpected input, or whatever. As written, the script erroneously assumes it's in the list; instead, it should check, but I don't see much need for a dedicated channel for the radiostation dialog, and not much opportunity for elaborate message coding of text that must appear on dialog buttons.

EDIT TO ADD: Oh, right: "the dialog problem" -- being that the radio script gets the UUID of whatever contains the main menu script, not the UUID of the tenant.  So, instead of passing just "request:radio" in that message, you'll also need to pass the user's key (tenantkey, which == id in the main menu's listen event handler), and then in the radio script parse it out of the received message string and cast it back into a key for use in llDialog.

Link to comment
Share on other sites

well i got it working now,

im listening on two channels but thats the only way im capable of doing it myself and only way i see even possible

without further complications

llListen(-5430, "", NULL_KEY, "");
llListen(-1000, "", NULL_KEY, "");

if it works it works i guess, not happy about it but you spotted even more problems hmm

im sure i wont use -5430 channel for anything else however thier could be a problem if someone else in the sim did.

very unlikely i know but yea.i guess i can also USERID == llKey2Name(name) in this situation

 

            llSay(secretchannel,"request:" +message+ "|" + (string)id);

 

 listen(integer channel, string name, key id, string message) {        list data = llParseStringKeepNulls(message, ["|"], []);        message = llList2String(data, 0);        if (channel == -1000 && message == "request:Radio")         {        key USERID = llList2String(data, 1);        llDialog(USERID, "\npick a station", _radioStations, -5430);        }        if (channel == -5430) {        string newURL = llList2String(_radioURLs, llListFindList(_radioStations, [message]));        llSay(0, message + " ---> " + newURL);        llSetParcelMusicURL(newURL);    }

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4332 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...