+Skippy and Pingu Posted July 7, 2015 Share Posted July 7, 2015 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. Quote Link to comment
+The GeoSpy Posted July 7, 2015 Share Posted July 7, 2015 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. Quote Link to comment
Ranger Fox Posted July 8, 2015 Share Posted July 8, 2015 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 Quote Link to comment
Geo-Magician Posted July 8, 2015 Share Posted July 8, 2015 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 Quote Link to comment
+Skippy and Pingu Posted July 8, 2015 Author Share Posted July 8, 2015 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. Quote Link to comment
+Skippy and Pingu Posted July 8, 2015 Author Share Posted July 8, 2015 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 . 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. Quote Link to comment
+sTeamTraen Posted July 8, 2015 Share Posted July 8, 2015 Please consider joining the Earwigo support Google Group --- joining details were included in your welcome e-mail. It's probably better for all concerned if we discuss support questions there, I think. Quote Link to comment
+Skippy and Pingu Posted July 9, 2015 Author Share Posted July 9, 2015 (edited) Please consider joining the Earwigo support Google Group --- joining details were included in your welcome e-mail. It's probably better for all concerned if we discuss support questions there, I think. Have found it and sent a request to join now. Edited July 9, 2015 by Skippy and Pingu Quote Link to comment
Recommended Posts
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.