Jump to content

Some help with a script


Laufiair Hexicola
 Share

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

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

Recommended Posts

Evening everyone, putting a script together that'll go into a physical magazine rack(it's 1li so nothing's movable). When a visitor comes along, they buy from the rack and are presented with a menu where they can choose what they want.. only my secondary buttons don't seem to be doing anything when called from the mainmenu.

I admit this is a mishmash of scripting and can generally follow along to get done what I'm looking to do, but this one confuses me so if there's anyone out there willing to help, would be appreciated.

-Logan
 

Quote

 

integer price = 20;

string mainMenuDialog = "Thank you for your purchase, please make a selection.";

list mainMenuButtons = ["Magazines", "Close"];

string subMenu_01_Dialog = "MAGAZINES\nNot Implemented yet.";
list subMenu_01_Buttons = ["Close"];
 

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

integer dialogChannel;
integer dialogHandle;
 
open_menu(key inputKey, string inputString, list inputList)
{
    dialogChannel = (integer)llFrand(DEBUG_CHANNEL)*-1;
    dialogHandle = llListen(dialogChannel, "", inputKey, "");
    llDialog(inputKey, inputString, inputList, dialogChannel);
    llSetTimerEvent(30.0);
}

close_menu()
{
    llSetTimerEvent(0);
    llListenRemove(dialogHandle);
}

default
{
    state_entry()
    {
        llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_DEBIT)
            state cash;
    }
    on_rez(integer start_param)
    {
        llResetScript();
    }
      touch_start(integer numDetected)
    {        
        key id = llDetectedKey(0);
        close_menu();
        open_menu(id, mainMenuDialog, mainMenuButtons);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(channel != dialogChannel)
            return;
 
        close_menu();
 
        if(message == "Ok")open_menu(id, mainMenuDialog, mainMenuButtons);
        else if(message == "Previous")open_menu(id, mainMenuDialog, mainMenuButtons);        
        else if(message == "Magazines")open_menu(id, subMenu_01_Dialog, subMenu_01_Buttons);                                                                                
    }
              
    timer()
    {
        close_menu();
    }
}

state cash
{
    state_entry()
    {
        llSetPayPrice(price, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
    }
    money(key id, integer amount)
    {
        if(amount != price)
        {
            llGiveMoney(id, amount);
            llInstantMessage(id, "You paid "+(string)amount+", which is the wrong price. The price is: "+(string)price);
        }
        else
        {
            llInstantMessage(id, "Thank you for your purchase!");
            open_menu(id, mainMenuDialog, mainMenuButtons);
        }
    }
}

 

 

Link to comment
Share on other sites

It's awkward without the standard indentation to read, but I think the problem is in your listen event. After you test for the channel being the dialog channel you then call close_menu, which effectively destroys the listen event before moving onto processing the message it has received.

Try putting it in a further else option at the very end of the listen event so that the listener is removed only if none of the other options have been matched.

Another tip is to stop the timer event at the very entry to the listen event so that it doesn't trigger during the processing if the user has spent a long time reading the buttons.

Edited by Profaitchikenz Haiku
typos as usual
Link to comment
Share on other sites

I don't understand the logic of the script at all, but the most obvious problem is that you request debit permissions in state entry and then, as soon as the owner grants them, you go into state cash, so neither the listen nor the touch events are ever going to fire.   

So all the script can do at the moment is wait for me to pay something and then either tell me I've paid the wrong amount or open a menu.   But the menu doesn't do anything -- there's no listen event in state cash to process whatever message it's expecting to hear when I use the menu.

Edited by Innula Zenovka
Link to comment
Share on other sites

3 hours ago, Innula Zenovka said:

I don't understand the logic of the script at all, but the most obvious problem is that you request debit permissions in state entry and then, as soon as the owner grants them, you go into state cash, so neither the listen nor the touch events are ever going to fire.   

So all the script can do at the moment is wait for me to pay something and then either tell me I've paid the wrong amount or open a menu.   But the menu doesn't do anything -- there's no listen event in state cash to process whatever message it's expecting to hear when I use the menu.

Exactly, thanks for hitting it right on the head. I took a menu script that already works and attempted to add a way so a visitor would have to pay the object first, then get the menu(which is why I call the menu at the very bottom). I did try to put the state cash up in the script but it gave a syntax error, so I figured I'd come to the forums and ask for some help in getting this script to work right. The point of the script is that it sits in a 1li magazine display and visitors pay the display first, then are allowed to make a selection. When I pay, it gives me the main dialog but then hangs when I choose a button other then close(like it's waiting for the pay event again). I'm just not sure how to go about correcting this.

Link to comment
Share on other sites

5 hours ago, Profaitchikenz Haiku said:

It's awkward without the standard indentation to read, but I think the problem is in your listen event. After you test for the channel being the dialog channel you then call close_menu, which effectively destroys the listen event before moving onto processing the message it has received.

Try putting it in a further else option at the very end of the listen event so that the listener is removed only if none of the other options have been matched.

Another tip is to stop the timer event at the very entry to the listen event so that it doesn't trigger during the processing if the user has spent a long time reading the buttons.

I did try and look for the button or code that let me do that but was unable to find it, so used quote. Apologies there. I have tried messing with the placement of the state but every time i move it to anyplace other then where it is, it throws a syntax error. Shortening or eliminating the timer event doesn't do anything.

Link to comment
Share on other sites

Think about the logic of the script (working out that script's logic is the main part of scripting -- writing it is secondary, to my mind).

Personally, I don't like vendor scripts that give refunds. I'd much rather ask people to contact the owner direct if they somehow pay the wrong amount, since it's simpler and it's more secure, but let's keep the refund for the purposes of this script.

The reason, I take it, for having two states is to ensure that it never gets as far as taking anyone's money unless it has permission to give them a refund if necessary.   Fair enough.   In that case, you need to request debit permissions in state entry of state default (which you do) and then, in the run_time_permissions event, once you've been granted debit permissions, move into state cash.   That way, nothing can happen until you've been granted the debit permission.

Once you arrive in state cash, call llSetPayPrice in state_entry there, and simply move the existing on_rez, touch_start, listen and timer events from state default down into state cash.

I don't see where you're getting the names of the magazines from, though, from which the customer can choose, and neither do I see what the script is going to do when I do choose a magazine, but maybe that part isn't written yet.

  • Thanks 2
Link to comment
Share on other sites

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