Difference between revisions of "User confirm"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
imported>StDoodle
Line 1: Line 1:
'''[[boolean]] user_confirm( [[string]] message )'''
+
{{#vardefine:name|user_confirm}}
<br />Opens a confirm dialog with the passed message; returns true if user selects Yes, false if No is pressed.
+
{{#vardefine:return_type|boolean}}
  
<p>Example:
+
{{FunctionPage|
<pre># fairly simple function to check if your bounty is one that gives good meat
+
name={{#var:name}}|
# if so, it makes sure that you want to farm meat and not stats.
+
function_category=Miscellaneous|
void equip_best_outfit(location bounty_area, string stat_outfit, string farming_outfit)
 
{
 
  
  if (bounty_area == $location[Giant's Castle] || bounty_area == $location[Fantasy Airship])
+
function1={{Function|
  {
+
name={{#var:name}}|
 
+
aggregate={{#var:aggregate}}|
    if (user_confirm("Your selected bounty area is a good source of meat. Would you like to use your farming outfit instead of your bounty outfit?")) return outfit(farming_outfit);
+
return_type={{#var:return_type}}|
 
+
return_also={{#var:return_also}}|
  }
+
parameter1={{Param|string|message}}|
 +
p1desc={{pspan|message}} is the text to display in the confirmation pop-up|
 +
}}|
  
  return outfit(stat_outfit);
+
function_description=Presents the user with a pop-up dialog box with the text in {{pspan|message}} (can use escaped characters, such as "<nowiki>\n</nowiki>" for a newline); returns true if the user selects "Yes" and false if the user selects "No."</p>
 +
<p>Please use these sparingly, as it can defeat the purpose of scripting if the user must constantly provide information during execution.|
  
}</pre></p>
+
code1={{CodeSample|
 +
title=Code Sample|
 +
description=A check to see if the user truly wants to execute a script.|
 +
code=
 +
<syntaxhighlight>
 +
if (!user_confirm("Are you sure you want to proceed with executing this script?") {
 +
  abort("Script execution canceled by user.");
 +
</syntaxhighlight>}}|
 +
 
 +
}}

Revision as of 19:32, 4 March 2010



Function Syntax

boolean user_confirm(string message )

  • message is the text to display in the confirmation pop-up

Presents the user with a pop-up dialog box with the text in message (can use escaped characters, such as "\n" for a newline); returns true if the user selects "Yes" and false if the user selects "No."

Please use these sparingly, as it can defeat the purpose of scripting if the user must constantly provide information during execution.

Code Sample

A check to see if the user truly wants to execute a script.

if (!user_confirm("Are you sure you want to proceed with executing this script?") {
  abort("Script execution canceled by user.");