Difference between revisions of "var.store"
Jump to navigation
Jump to search
Jimbauwens (talk | contribs) (Created page with "var.'''store''' is a function that is part of the Var Library. <br> The function set the content of a variable in the current document. Returns nil when the operation su...") |
m (→Example) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | var.'''store''' is a function that is part of the Var | + | var.'''store''' is a function that is part of the [[:Category:var|Var]] functions. |
<br> | <br> | ||
+ | The function set the content of a variable in the current document.<br /> | ||
+ | Returns nil when the operation succeeded, otherwise an error message. | ||
− | + | == Syntax == | |
− | + | var.'''store'''(varname, data) | |
− | + | {| class="wikitable" | |
+ | |- | ||
+ | ! Parameter !! Type !! Description | ||
+ | |- | ||
+ | | <u><center>varname</center></u> || string || The name of the ''math'' variable you want to store stuff in. | ||
+ | |- | ||
+ | | <u><center>data</center></u> || anything || the data you want to store in ''varname''. Can be a number, string, table etc. | ||
+ | |- | ||
+ | |} | ||
== Example == | == Example == | ||
− | + | --[[User:Adriweb|Adriweb]] ([[User talk:Adriweb|talk]]) 11:33, 14 April 2016 (CEST) | |
<source lang="lua"> | <source lang="lua"> | ||
− | function on. | + | function on.construction() |
− | var.store("sol", | + | var.store("sol", 1400000) |
end | end | ||
Line 22: | Line 32: | ||
</source> | </source> | ||
− | This code retrieves the content of the variable sol (string), and prints it on the screen. | + | This code store some data into the "sol" variable, retrieves the content of the variable sol (string), and prints it on the screen. |
== See also == | == See also == |
Latest revision as of 10:33, 14 April 2016
var.store is a function that is part of the Var functions.
The function set the content of a variable in the current document.
Returns nil when the operation succeeded, otherwise an error message.
Syntax
var.store(varname, data)
Parameter | Type | Description |
---|---|---|
string | The name of the math variable you want to store stuff in. | |
anything | the data you want to store in varname. Can be a number, string, table etc. |
Example
--Adriweb (talk) 11:33, 14 April 2016 (CEST)
function on.construction()
var.store("sol", 1400000)
end
function on.paint(gc)
variable = var.recall("sol") --assuming that sol exists
gc:drawString("The diameter of the sun is " .. tostring(variable) .. " KM", 10, 10, "top")
end
This code store some data into the "sol" variable, retrieves the content of the variable sol (string), and prints it on the screen.