Scripting - Chapter 3: Variables

From PlayOnLinux
Revision as of 00:31, 27 February 2015 by RoninDusette (talk | contribs) (Page créée avec « == Variable? Is that a new insult? == No, it's not an insult. The variable is a very important element in programming. It is defined by a name and a value. This value can... »)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Variable? Is that a new insult?

No, it's not an insult. The variable is a very important element in programming. It is defined by a name and a value. This value can vary along the script.

If you don't understand, keep on reading and you'll find out what it's all about.

Declaring a variable

MY_VARIABLE="My value"

Reading a variable

You have to put this sign "$" in front of the variable.

Example:

FRUIT="pear"
 
POL_SetupWindow_message "I like to eat a $FRUIT" "My favourite fruit"

Result:

PlayOnLinux Wizard My favourite fruit

I like to eat a pear

You can use variables in any message, menu, etc.

POL_SetupWindow_menu and variables

Do you remember this code?

POL_SetupWindow_menu "What do you want to eat tonight?" "Tonight's menu" "Carrots Potatoes French-fries" " "

The result is actually sent to the variable $APP_ANSWER. This is the way to retrieve user's choice:

POL_SetupWindow_menu "What do you want to eat tonight?" "Tonight's menu" "Carrots Potatoes French-fries" " "
 
POL_SetupWindow_message "Tonight we'll be eating $APP_ANSWER, a very good choice." "Tonight's menu"

POL_SetupWindow_browse and variables

For POL_SetupWindow_browse, it is the path to the file selected by the user that is stored into $APP_ANSWER.

POL_SetupWindow_question and variables

For POL_SetupWindow_question, $APP_ANSWER will contain TRUE if the user answered yes, and FALSE if (s)he answered no.