Jump to content

Dataserver Help


Shymus Roffo
 Share

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

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

Recommended Posts

I've been trying to set listen channels with notecard and i just can't figure out why the channel stays on 0 when it switches states

string notecard = "_config";
integer iline = 0;
key kquery;
integer channel = -5533;

default{
    state_entry(){
        if(llGetInventoryNumber(INVENTORY_NOTECARD)>1){
            llOwnerSay("No notecard named: "+notecard+" In the inventory");
            state missinginfo;
        }else{
            llOwnerSay("Reading Notecard.....");
            kquery = llGetNotecardLine(notecard,iline);
        }
    }changed(integer change){
        if(change & CHANGED_INVENTORY){
            llResetScript();
        }
    }dataserver(key queryid, string data){
        if(queryid == kquery){
            if(data!=EOF){
                data = llStringTrim(data, STRING_TRIM_HEAD);
                if(llGetSubString(data, 0,0)!="#"){
                    integer s = llSubStringIndex(data, "=");
                    if(~s){
                        string token = llToLower(llStringTrim(llDeleteSubString(data, s, -1), STRING_TRIM));
                        if(token=="channel")
                            channel = (integer)data;
                        }
                    }
                }else{
                state ready;
            }
            kquery = llGetNotecardLine(notecard,++iline);
        }
    }
}
state ready{
    state_entry(){
        llListen(channel, "","","");
        llOwnerSay("Channel : "+(string)channel);
    }changed(integer ch){
        if(ch & CHANGED_INVENTORY){
            llResetScript();
        }
    }
}
state missinginfo{
    state_entry(){
        if(llGetInventoryNumber(INVENTORY_NOTECARD)==1)
            llResetScript();
    }changed(integer c){
        if(c & CHANGED_INVENTORY){
            llResetScript();
        }
    }
}

 

Link to comment
Share on other sites

 

    See embedded code comments. Don't feel bad, lotsa very experienced programmers make ooops like this :)

 

if(llGetSubString(data, 0,0)!="#")
{
//looking for the "=" sign in a string data
integer s = llSubStringIndex(data, "=");
if(~s)
{
//found one!
string token = llToLower(llStringTrim(llDeleteSubString(data, s, -1), STRING_TRIM));
// token is whatever before the "=" sign in a string data
if(token=="channel")
// it is word "channel"
channel = (integer)data;
// data string still starts with word "channel" because it was never changed
// so if cast to integer it is of course a 0  
}
}
Link to comment
Share on other sites

The way I see it is this:

The notecard line reads: -124587 = channel

The script divides that line on "=" and checks the part after that.
If that is "channel" then the first part of the data string must be the number. 

 

Aha. I see my error.

I thought:   llDeleteSubString(data, s, -1) returns the part of the string from "=" to the end, but it returns the remaining part.

So the scriptline should read:

    string token = llToLower(llStringTrim(llGetSubString(data, s, -1), STRING_TRIM));

And the other line should then be:

channel = (integer)(llStringTrim(llGetSubString(data, 0, s - 1), STRING_TRIM));

 

I think :)

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...