Jump to content

Message: Two buttons, one script?


sTeamTraen

Recommended Posts

A Message can have two buttons. The Tutorial says:

 

Example:

If 'Button1' is clicked on a Message Box

Do some action 'A'

Else If 'Cancel' is clicked on a Message Box

Do some other action 'B'

 

There are three potential results of this example:

The player presses 'Button1' and the Button1 action executes (do action 'A')

The player presses 'Cancel' and the Cancel action executes. (do action 'B')

Some other UI element overlays the message box and the Cancel action executes (do action 'B')

 

But the builder only allows me to specify one action for a message box (unless I'm missing something).

- Does this apply to Button1 or Button2?

- How can I specify actions 'A' and 'B', as the tutorial indicates?

Link to comment

Create your message box and tick the checkboxes for the two buttons

 

Then click the 'script to run when button clicked'

 

enter a group name as usual

 

now click add IF-THEN-ELSE

 

select 'if a button is clicked on a message box'

 

You can now choose which button you want to do what action :o

Link to comment

When you create a message box look at the bottom left hand corner on the screen where you enter the message. You'll see two check boxes there. If you want two buttons check both of them and enter the label for each button. Then click on the "Script to run when button clicked..." box and it will bring up the area where you put in the code as you describe. I haven't messed with "Cancel" yet.

Link to comment

Okay, that's becoming clearer, although it's a little counterintuitive.

 

Now I have this question:

 

If my script for the message box just says

increment myvar by 3

then this code is generated in the callback function:

 

if action ~= nil then
-- #GroupDescription=Script --
-- #Comment=Script Comment --
myvar = myvar + 3
end

 

(The "if" statement being before the comments may give a clue to the "default" nature of the action here)

 

However, if the script says

  increment myvar by 3
 if the user clicked Cancel, decrement myvar by 4

then the code is:

 

-- #GroupDescription=Script --
-- #Comment=Script Comment --
myvar = myvar + 3
if action == nil then
myvar = myvar - 4
end

 

One of these looks wrong - probably the first one, because myvar is not incremented by 3 if the user clicks Cancel, but that wasn't what I specified.

Link to comment

However, if the script says

 

 increment myvar by 3
 if the user clicked Cancel, decrement myvar by 4

 

then the code is:

-- #GroupDescription=Script --
-- #Comment=Script Comment --
myvar = myvar + 3
if action == nil then
myvar = myvar - 4
end

 

One of these looks wrong - probably the first one, because myvar is not incremented by 3 if the user clicks Cancel, but that wasn't what I specified.

 

From your post, it seemed as though you wanted myvar to be incremented if the user clicks Cancel. In that case, the generated code should look like this

(action == nil means the user chose cancel):

 

-- #GroupDescription=Script --
-- #Comment=Script Comment --
if   action == "Button1" then
Wherigo.MessageBox{Text=[[a]],}
end
if   action == "Button2" then
Wherigo.MessageBox{Text=[[b]],}
end
if   action == nil then
myvar = myvar + 3
end
end

 

Which means, it needs to be scripted this way:

 if the user clicked Cancel,
 increment myvar by 3

 

Does this help? Let us know! :anitongue:

 

J2B2

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...