Jump to content

Vendor Scripting Help


Brooklyn Drascol
 Share

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

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

Recommended Posts

Hello all,

I came across Kristy Fanshaw's shortened vendor system scripting on SL's wiki page. When I uploaded them in-world and attempted to save, I came across scripting line errors. One of them in the 'Vendor' script is this one:

          llEmail( body, ID, (string)llGetKey()+"@lsl.secondlife.com" );

The only other scripting error that I have come across is the following in the 'Server' script:

          totalsold = (integer)llGetObjectDesc();

I have attached the entirity of the codes below for your convience, I really hope that someone can help me figure out these issues and the possibility of further problems I may run across.

Thanks everyone!

 

///// PLACE THIS SCRIPT IN A VENDOR ROOT PRIM YOU'VE CREATED /////


integer gCorrectAmount = 10;                            // enter the price for fast pay
integer my_profit = 50;                                 // how many percent you would like to recieve form the sale
string update_box = "update box name";                  // describe the name of the "update box" object that should be rezzed
string name = "my vendor name";                         // Set the vendor name here
 
integer totalsold = 0;
integer Ch;
integer listen_handle;
integer buyer_paid;
key OWNER;
key CREATOR;
key ID;
key http_request_id;
string mail;
 
default
    {
        changed(integer change)
            {
                if(change & CHANGED_OWNER)
                    {
                        llSetObjectDesc("0");
                        llResetScript();
                    }
            }
        on_rez(integer start_param)
            {
                llResetScript();
            }
        state_entry()
            {
                OWNER = llGetOwner();
                CREATOR = llGetCreator();
                Ch =  ( -1 * (integer)("0x"+llGetSubString((string)CREATOR,-7,-1)) );
                totalsold = (integer)llGetObjectDesc();
                llSetObjectName(name);
                llSetPayPrice(PAY_HIDE, [gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                llSetText("To start vendor, rezz '" + update_box + "'.", <1.0, 1.0, 1.0>, 1.0);
                llSensorRepeat(update_box, NULL_KEY , SCRIPTED, 10 , PI, 10);
            }
        sensor (integer numberDetected)
            {
                state sens;
            }
        no_sensor ()
            {
                llResetScript();
            }
    }
state sens1
    {
        state_entry()
            {
                state sens;
            }
    }
state sens
    {
        on_rez(integer start_param)
            {
                llResetScript();
            }
        state_entry()
            {
                llSetText("Updating", <1.0, 1.0, 1.0>, 1.0);  
                llShout(Ch,"update");
                listen_handle = llListen(Ch,update_box, NULL_KEY, "");
                llSensorRepeat(update_box, NULL_KEY , SCRIPTED, 10 , PI, 5);
            }
        listen( integer channel, string name, key id, string message )
            {
                 mail = message;
                 llOwnerSay("updated");
                 llShout(Ch,"updated");
                 llListenRemove(listen_handle);     
            }
        sensor (integer numberDetected)
            {
                llListenRemove(listen_handle);
                state sens1;
            }
        no_sensor ()
            {
                llSetText("Touch to grant debit permission.", <1.0, 1.0, 1.0>, 1.0);
            }
        touch_start(integer total_number)
            {
                llRequestPermissions(OWNER, PERMISSION_DEBIT);
            }
        run_time_permissions(integer Permission)
            {
                if(Permission == PERMISSION_DEBIT)
                    {
                        llOwnerSay("Starting vendor.");
                        llSetText("", <1.0, 1.0, 1.0>, 1.0);
                        state Ready;
                    }
                else
                    {
                        llOwnerSay ( "To share proceeds I must have give money(DEBIT) permissions");
                        llOwnerSay ( "Try again");
                        llResetScript();
                    }
            }  
    } 
state Ready1
    {
        state_entry()
            {
                state Ready;
            }
    }
state Ready
    {
        on_rez(integer start_param)
            {
                llResetScript();
            }
        state_entry()
            {
                llSensorRepeat(update_box, NULL_KEY , SCRIPTED, 10 , PI,30);
            }
        sensor (integer numberDetected)
            {
                llSetText("Updating", <1.0, 1.0, 1.0>, 1.0);
                llShout(Ch,"update");
                listen_handle = llListen(Ch,update_box, NULL_KEY, "");
            }
        listen( integer channel, string name, key id, string message )
            {
                mail = message;
                llOwnerSay("updated");
                llShout(Ch,"updated");
                llSetText("", <1.0, 1.0, 1.0>, 1.0);
                llListenRemove(listen_handle);
            }
        touch_start(integer total_number)
            {
                if (llDetectedOwner(0) == OWNER)
                    {
                        llOwnerSay((string)totalsold +" units have been sold since object rez. ");
                    }
                else
                    {
                        llInstantMessage(llDetectedKey(0), "Right-click and pay to purchase."); 
                    }
            }
        money(key id, integer amount)
            {
                ID =id;
                buyer_paid = amount;
                    {
                        if (amount == gCorrectAmount)
                            {
                                llInstantMessage(id, "Thank you " + llKey2Name(id) + " for your purchase.");
                                llInstantMessage(ID,"Sending your requested items .....");
                                llSetText("Purchase in progress...\n\nPlease Wait...", <1.0, 1.0, 1.0>, 1.0);
                                llSetPayPrice(PAY_HIDE,[ PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                                llEmail( body, ID, (string)llGetKey()+"@lsl.secondlife.com" );
                                llSetTimerEvent(5);
                                llGetNextEmail("", "");     
                            }
                        else if (amount < gCorrectAmount)
                            {
                                llInstantMessage(llDetectedKey(0),"You didn't pay enough, " + llKey2Name(id) + ". Refunding your payment of L$" + (string)amount + ".");
                                llGiveMoney(id, amount);
                                state Ready1;
                            }
                        else
                            {
                                integer refund = amount - gCorrectAmount;
                                llInstantMessage(llDetectedKey(0),"You paid too much, " + llKey2Name(id) + ". Your change is L$" + (string)refund + ".");
                                llGiveMoney(id, refund);
                                llInstantMessage(id, "Thank you " + llKey2Name(id) + " for your purchase.");
                                llInstantMessage(ID,"Sending your requested items .....");
                                llSetText("Purchase in progress...\n\nPlease Wait...", <1.0, 1.0, 1.0>, 1.0);
                                llSetPayPrice(PAY_HIDE,[ PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                                llEmail( body, ID, (string)llGetKey()+"@lsl.secondlife.com" );
                                llSetTimerEvent(5);
                                llGetNextEmail("", "");     
                            }
                    }
            }
        email( string time, string address, string subj, string message, integer num_left )
            {    
                if (subj == "delivered")
                    {
                        float profit = (my_profit + 0.0) / 100;
                        float calc = buyer_paid + 0.0;
                        float a = calc * profit;
                        float b = buyer_paid - a;
                        llGiveMoney( CREATOR, llFloor((integer)a) );
                        llInstantMessage(ID,"Accept your purchased items");
                        totalsold = totalsold + 1;
                        llSetObjectDesc((string)totalsold);
                        llInstantMessage(OWNER, (string)llKey2Name(ID) + " has paid " + (string)buyer_paid + "L$ in "+ llGetRegionName() + " and you have recived " + (string)llCeil(b) + "L$ from this sale");
                        llInstantMessage(CREATOR, (string)llKey2Name(ID) + " has paid " + (string)buyer_paid + "L$ in "+ llGetRegionName() + " and you have recived " + (string)llFloor(a) + "L$ from this sale");
                        llSetPayPrice(PAY_HIDE,[gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                        llSetText("", <1.0, 1.0, 1.0>, 1.0);
                        llSetTimerEvent(0);
                        state Ready1;
                    }  
            }
        timer() 
            {       
                llGiveMoney(ID, buyer_paid);
                llInstantMessage(ID, "Vendor couldn't deliver items ... your money is refunded");
                llInstantMessage(OWNER, "Your Vendor in " + llGetRegionName() + " sim can't deliver items. Please update your Vendor.");
                llSetPayPrice(PAY_HIDE,[gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                llSetText("", <1.0, 1.0, 1.0>, 1.0);
                llSetTimerEvent(0);
                state default;         
            }                           
}



///// PLACE THIS SCRIPT IN A BOX YOU'VE CREATED /////


string mail = "00000000-0000-0000-0000-000000000000@lsl.secondlife.com";                  // Write here the server email address which is "serverobject-prim-key@lsl.secondlife.com"
string update_box = "update box name";                                                    // Write here the name you like, but be sure the name here matches with a name in vendor script
integer Ch;
integer listen_handle;
 
default
    {
        state_entry ()
            {
                Ch =  ( -1 * (integer)("0x"+llGetSubString((string)llGetCreator(),-7,-1)) );
                listen_handle = llListen(Ch,"", NULL_KEY, "");
                llSetObjectName(update_box);
                llSetText("Updating your vendor\n\nPlease Wait ...", <1.0, 1.0, 1.0>, 1.0);
            }
        listen( integer channel, string name, key id, string message )
            {
                if(message == "update")
                    {
                        llShout(Ch, mail);
                    }        
                else if (message == "updated")
                    {
                        llDie();
                    }
            }
}



///// PLACE THESE SCRIPTS INTO A BOX YOU'VE CREATED AS A SERVER PRIM. PLACE THE OBJECTS YOU'D LIKE TO SELL INTO THIS PRIM - ONLY ONE OBJECT. /////


string my_address = "my.email@email.com";       // Write here the email, where you want to recieve the message with new server email address.
integer total_mailers = 5;                      // How many mailer scripts you have in server prim. 5 mailer scripts are Recomended min. because of llEmail function.
integer mailer = 1;                             
 
default
    {
        changed(integer change)
            {
                if(change && CHANGED_OWNER)
                    {
                        llSetObjectDesc("0");
                        llResetScript();
                    }       
            }
        on_rez(integer start_parameter)
            {
                llOwnerSay("new email is: " + (string)llGetKey() + "@lsl.secondlife.com");
                llEmail(my_address,llGetObjectName() , "my new email is: " + (string)llGetKey() + "@lsl.secondlife.com");
                llOwnerSay("message with new address is sent to your email");
            }
        state_entry()
            {               
                llSetObjectName(llGetInventoryName(INVENTORY_OBJECT,0));
                llSetText(llGetObjectName(),<1,1,1>,1);
                totalsold = (integer)llGetObjectDesc();
                llOwnerSay("new email is: " + (string)llGetKey() + "@lsl.secondlife.com");
                llEmail(my_address,llGetObjectName() , "my new email is: " + (string)llGetKey() + "@lsl.secondlife.com");
                llOwnerSay("message with new address is sent to your email");
                llSetTimerEvent(5.0);               
            } 
        timer()
            {
                llGetNextEmail("", "");
            }
        email( string time, string address, string subj, string message, integer num_left )
            {
                llGiveInventory(subj,llGetInventoryName(INVENTORY_OBJECT,0) );
                message = llDeleteSubString(message, 0, llSubStringIndex(message, "\n\n") +1);
                llMessageLinked(LINK_THIS, mailer, message, "");
                if (mailer <= total_mailers)
                    {
                        mailer = mailer + 1;
                    }
                if (mailer >= total_mailers + 1)
                    {
                        mailer = 1;  
                    }
                totalsold = totalsold + 1;
                llSetObjectDesc((string)totalsold);
                llGetNextEmail("", "");
            }
        touch_start(integer total_number)
            {
                if (llDetectedOwner(0) == llGetOwner())
                    {
                        llOwnerSay((string)totalsold +" units have been sold since server update. ");
                    }
                else
                    {
                        llInstantMessage(llDetectedKey(0), "please don't touch"); 
                    }
            }
}



///// MAILER SCRIPT (PLACE IN SAME PRIM AS 'SERVER' SCRIPT) /////


string mailer_num;
 
default
    { 
        link_message(integer sender_num, integer num, string msg, key id) 
            {
                mailer_num = llGetScriptName();
                if (num == (integer)mailer_num)
                    {
                        llEmail(msg,"delivered", (string)num);
                    }
            }
}

 

Link to comment
Share on other sites

I didn't go through the scripts in detail - but here are the obvious points:

 

  1. llEmail - the order of the arguments seems to wrong - look in the wiki
  2. apart from the fact that the address should come fist, then the subject should follow and finally the message body, the variabe body in llEmail never gets declared neither does it get set.
  3. in the third script, the variable total_sold never gets declared
  • Like 1
Link to comment
Share on other sites

I peeked into the wiki posting of that script, and every version back to the first posting has (at least) that same problem. It's rather an odd case where much editing was done over several months to source code that could never have worked at all.

I'd suggest starting with a different script, if not from scratch.

FWIW, the problematic llEmail() statement appears to derive from the same wiki-poster's other vendor script, in which the "body" variable is bound in an http comms event.

Link to comment
Share on other sites

Yes, as soon as I attempt to save the script, it pops up with the failures in my first post. But it states their exact location in the script itself - which is very helpful. The total errors I get are 2:

(175, 45) : Error : Name not defined within scope  -  This one is within the "vending" and then the "server" script. The server exactment is (41, 26). Both errors deals with the 'TotalSold' and the 'llEmail' coding.

Link to comment
Share on other sites

"Name not defined in scope" means that the variable wasn't declared, or wasn't declared within the same event, or otherwise the same "scope."

 

For example:

touch_start(integer num) {    if (num) {        string s = "Two or more people touching!";    }    llOwnerSay(s);}

 In this case, the string s is defined within the if block. The if block exits, s becomes undefined. Thus, this would get the error "name not defined in scope."

A correct version is as follows:

touch_start(integer num) {    string s;    if (num) {        s = "Two or more people touching!";    }    llOwnerSay(s);}

 In this case, it's defined before the block, and then assigned during, and used afterwards. Since it's defined within the "touch_start()" scope, it's within the same scope.

Trying to use this variable in another event would require defining it as a global variable, before the state definition. Like so:

integer i;default {    touch_start(integer num) {        i = i + 1;    }    on_rez(integer a) {        llOwnerSay("We have been touched "+(string)i+" times.");    }}

 Understanding scope and variable definition should help you resolve this problem.

 

 

Link to comment
Share on other sites


Stickman Ingmann wrote:

"Name not defined in scope" means that the variable wasn't declared, or wasn't declared within the same event, or otherwise the same "scope."
[....]

 Understanding scope and variable definition should help you resolve this problem.

 


Good description, but it's not likely to help in this case.  That script is a mess.  It needs more than just a variable definition.

Link to comment
Share on other sites

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