turtlestitch/libraries/make-variables.xml

1 wiersz
14 KiB
XML
Czysty Zwykły widok Historia

<blocks app="Snap! 6.0 beta, https://snap.berkeley.edu" version="1"><block-definition s="create %&apos;scope&apos; var %&apos;names&apos;" type="command" category="variables"><comment x="0" y="0" w="146" collapsed="false">This block creates new variables on the selected scope: global (for all sprites), sprite (for this sprite only) or script (only for that blocks stack) with the names given (in &apos;names&apos; list).&#xD;&#xD;If there is already a variable with that name in that scope, it does nothing: no errors and no overwrites.</comment><header></header><code></code><translations>pt:cria as variáveis _ _&#xD;ca:crea les _ variables _&#xD;es:crear las _ variables _&#xD;de:erstellen _ var _&#xD;</translations><inputs><input type="%s" readonly="true">global<options>global&#xD;sprite&#xD;script</options></input><input type="%mult%txt"></input></inputs><script><block s="doIfElse"><block s="reportEquals"><block var="scope"/><l>script</l></block><script><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {&#xD; throw new Error("name isn&apos;t a string: " + varName);&#xD;}&#xD;if (!proc.homeContext.variables.vars[varName]) proc.homeContext.variables.addVar(varName);</l></block><list><block var="each item"/></list></block></script></block></script><script><block s="doDeclareVariables"><list><l>global</l></list></block><block s="doIfElse"><block s="reportEquals"><block var="scope"/><l>sprite</l></block><script><block s="doSetVar"><l>global</l><block s="reportBoolean"><l><bool>false</bool></l></block></block></script><script><block s="doSetVar"><l>global</l><block s="reportBoolean"><l><bool>true</bool></l></block></block></script></block><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>global</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {&#xD; throw new Error("name isn&apos;t a string: " + varName);&#xD;}&#xD;if (global &amp;&amp; !proc.homeContext.variables.parentFrame.parentFrame.vars[varName]) this.addVariable(varName, true);&#xD;if (!global &amp;&amp; !proc.homeContext.variables.parentFrame.vars[varName]) this.addVariable(varName, false);</l></block><list><block var="each item"/><block var="global"/></list></block></script></block><block s="doRun"><block s="reportJSFunction"><list></list><l>var ide = this.parentThatIsA(IDE_Morph);&#xD;ide.flushBlocksCache(&apos;variables&apos;); // b/c of inheritance&#xD;ide.refreshPalette();</l></block><list></list></block></script></block></script></block-definition><block-definition s="delete var %&apos;names&apos;" type="command" category="variables"><comment x="0" y="0" w="217" collapsed="false">This block deletes all the variables with the names given (inside input list).&#xD;&#xD;Each name will make only one variable deletion, and this will be the variable found following the scope order: &apos;script&apos; -&gt; &apos;sprite&apos; -&gt; &apos;global&apos;.&#xD;&#xD;If we have a &quot;testing&quot; sprite variable and also a &quot;testing&quot; global one, deleting &quot;testing&quot; will delete only the sprite one (Yes! we can also do &quot;delete var (testing, testing)&quot; to delete both.&#xD;&#xD;If one variable does not exists (in any scope) an error happens, stopping block action in that point. You can check it before with the &quot;does var (name) exists?&quot;block. </comment><header></header><code></code><translations>pt:remove as variáveis _&#xD;ca:esborra les variables _&#xD;es:borrar variables _&#xD;de:löschen var _&#xD;</translations><inputs><input type="%mult%txt"></input></inputs><script><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {&#xD; throw new Error("name isn&apos;t a string: " + varName);&#xD;}&#xD;if (typeof proc.homeContext.var