<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://miniscript.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thacuber2a03</id>
	<title>MiniScript Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://miniscript.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Thacuber2a03"/>
	<link rel="alternate" type="text/html" href="http://miniscript.org/wiki/Special:Contributions/Thacuber2a03"/>
	<updated>2026-04-27T16:39:04Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>http://miniscript.org/w/index.php?title=Globals&amp;diff=1003</id>
		<title>Globals</title>
		<link rel="alternate" type="text/html" href="http://miniscript.org/w/index.php?title=Globals&amp;diff=1003"/>
		<updated>2022-09-09T20:03:58Z</updated>

		<summary type="html">&lt;p&gt;Thacuber2a03: it's a map, &amp;quot;globals isa map&amp;quot; returns 1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''globals''' is a built-in map that references [[variables]] at the global scope.  Any assignment outside of any function creates (or updates) an entry in the '''globals''' map.&lt;br /&gt;
&lt;br /&gt;
Inside a function, an unqualified assignment (i.e. an assignment to an identifier that does not follow a dot — like ''x'' rather than ''foo.x'') creates a local variable.  Local variables exist only within the function where they are created, and disappear as soon as the function exits.  This is true even if there happens to already be a global variable of the same name.&lt;br /&gt;
&lt;br /&gt;
So, when you want to create or update a global variable inside a function, the '''globals''' map must be used on the left-hand side of the assignment.&lt;br /&gt;
&lt;br /&gt;
See also: [[locals]]; [[outer]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The ''check'' function below compares its parameter to a global variable.  The comparison does not need the '''globals''' map, because it's only reading the value (and there is no local variable of the same name).  But when it updates the global value, it has to use '''globals'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ms&amp;gt;lastValue = null&lt;br /&gt;
check = function(someValue)&lt;br /&gt;
    if someValue != lastValue then&lt;br /&gt;
        print &amp;quot;The value is now: &amp;quot; + someValue&lt;br /&gt;
        globals.lastValue = someValue  // &amp;lt;--- Note use of globals&lt;br /&gt;
    end if&lt;br /&gt;
end function&lt;br /&gt;
&lt;br /&gt;
x = 0&lt;br /&gt;
while true&lt;br /&gt;
    check round(x)&lt;br /&gt;
    x = x + 0.1&lt;br /&gt;
    wait 0.1&lt;br /&gt;
end while&amp;lt;/ms&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also note that the [[while]] loop at the end is at the global scope, so it does not need to use '''globals''' at all; globals and locals are the same in this case.&lt;br /&gt;
&lt;br /&gt;
[[Category:Language]]&lt;br /&gt;
[[Category:Intrinsic Functions]]&lt;/div&gt;</summary>
		<author><name>Thacuber2a03</name></author>
		
	</entry>
</feed>