Jump to content

2 buttons in a message EARWIGO


Skippy and Pingu

Recommended Posts

I'm making a Wherigo using earwigo. I have a message with 2 buttons but I can't work out how to check which button was pressed to then trigger different things to happen depending on which button was pressed. At the moment the same thing happens regardless of which button is pressed. How do I check which button is pressed? Thanks.

Link to comment

I'm making a Wherigo using earwigo. I have a message with 2 buttons but I can't work out how to check which button was pressed to then trigger different things to happen depending on which button was pressed. At the moment the same thing happens regardless of which button is pressed. How do I check which button is pressed? Thanks.

What two buttons are you talking about? Could you provide a description or a picture.

Link to comment

I believe you are saying you have a dialog with two custom buttons on it and need to differentiate between which button was pressed.

 

I'm not sure how to do it in Earwigo, but I have attached an example cartridge. In short, the MessageBox is given an array of buttons. The MessageBox's callback function accepts an "action" variable. This is a string that contains the word "Button" and the number in the array (1 index), e.g. "Button1". Here's the relevant lua script:

 

function zoneZone:OnEnter()
 Wherigo.MessageBox{Text=[[selecting a button does different things.]],Buttons={"One","Two",},Callback=cartButtonexample.MsgBoxCBFuncs.MsgBoxCB2}
end

cartButtonexample.MsgBoxCBFuncs.MsgBoxCB2 = function(action)
 if   action == "Button1" then
   Wherigo.MessageBox{Text=[[You chose the first option.]],}
 else
   Wherigo.MessageBox{Text=[[You chose the second option.]],}
 end
end

button example.zip

Link to comment

I'm making a Wherigo using earwigo. I have a message with 2 buttons but I can't work out how to check which button was pressed to then trigger different things to happen depending on which button was pressed. At the moment the same thing happens regardless of which button is pressed. How do I check which button is pressed? Thanks.

 

Welcome to Earwigo. I assume you are talking about the two standard Buttons of a Message. Now you have to make a decision in the program code AKA If_Else_Endif. Knowing If_Else_Endif structures will help you to create awesome cartridges ;). Here is a link to the decision section of the tutorial http://earwigo.net/WWB/wiki/doku.php?id=create_your_first_cartridge#decisions_introduction

 

This is how to handle your specific case:


  •  
  • Prepare the usage of an If_Else_Endif decision structure. In order to do so in Earwigo you have to define an Expression that describes what you want to test for. In your case you can test for Button1Pressed.
  • Create the expression ButtonOnePressed (or any other name that helps you to remember what you are testing for.
  • Use the Properties/Conditions Section of the Expression to create the following test "Button was clicked Button 1"
  • Now go to the Message that has the two buttons.
  • Switch to the Messages/Events SubTab
  • Here you will find the Event "When a button is pressed"
  • Create the If_Then_Else logic for the button Event.
  • It will look like this

 

if ButtonOnePressed
  Your action number 1
Else
  your action number 2
EndIf

Link to comment

I believe you are saying you have a dialog with two custom buttons on it and need to differentiate between which button was pressed.

 

I'm not sure how to do it in Earwigo, but I have attached an example cartridge. In short, the MessageBox is given an array of buttons. The MessageBox's callback function accepts an "action" variable. This is a string that contains the word "Button" and the number in the array (1 index), e.g. "Button1". Here's the relevant lua script:

 

function zoneZone:OnEnter()
 Wherigo.MessageBox{Text=[[selecting a button does different things.]],Buttons={"One","Two",},Callback=cartButtonexample.MsgBoxCBFuncs.MsgBoxCB2}
end

cartButtonexample.MsgBoxCBFuncs.MsgBoxCB2 = function(action)
 if   action == "Button1" then
   Wherigo.MessageBox{Text=[[You chose the first option.]],}
 else
   Wherigo.MessageBox{Text=[[You chose the second option.]],}
 end
end

 

Thank you so much. I've loaded that into earwigo and seen what I need to do. Its worked and I'm happy because it means I can make my cartridge do exactly what I want. I thought I was going to have to simplify it and I didn't want to. Its an adventure fantasy style Wherigo.

Link to comment

I'm making a Wherigo using earwigo. I have a message with 2 buttons but I can't work out how to check which button was pressed to then trigger different things to happen depending on which button was pressed. At the moment the same thing happens regardless of which button is pressed. How do I check which button is pressed? Thanks.

 

Welcome to Earwigo. I assume you are talking about the two standard Buttons of a Message. Now you have to make a decision in the program code AKA If_Else_Endif. Knowing If_Else_Endif structures will help you to create awesome cartridges ;). Here is a link to the decision section of the tutorial http://earwigo.net/WWB/wiki/doku.php?id=create_your_first_cartridge#decisions_introduction

 

This is how to handle your specific case:


  •  
  • Prepare the usage of an If_Else_Endif decision structure. In order to do so in Earwigo you have to define an Expression that describes what you want to test for. In your case you can test for Button1Pressed.
  • Create the expression ButtonOnePressed (or any other name that helps you to remember what you are testing for.
  • Use the Properties/Conditions Section of the Expression to create the following test "Button was clicked Button 1"
  • Now go to the Message that has the two buttons.
  • Switch to the Messages/Events SubTab
  • Here you will find the Event "When a button is pressed"
  • Create the If_Then_Else logic for the button Event.
  • It will look like this

 

if ButtonOnePressed
  Your action number 1
Else
  your action number 2
EndIf

 

Thank you :anitongue: . That's really clear as well. I hope you don't mind me sharing this with a couple of friends who are also struggling with this.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...