<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Improving_Scripts</id>
	<title>Improving Scripts - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Improving_Scripts"/>
	<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;action=history"/>
	<updated>2026-06-13T13:41:39Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=2893&amp;oldid=prev</id>
		<title>Patarakin в 08:54, 9 сентября 2022</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=2893&amp;oldid=prev"/>
		<updated>2022-09-09T08:54:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:54, 9 сентября 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Строка 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Scripting Tutorials&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|Description=Как улучшать скрипты в своих проектах Scratch - делать их быстрее и понятнее.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|Field_of_knowledge=Информатика, Робототехника&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This article explains methods of &amp;#039;&amp;#039;&amp;#039;improving [[script]]s&amp;#039;&amp;#039;&amp;#039; for compaction and efficiency.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This article explains methods of &amp;#039;&amp;#039;&amp;#039;improving [[script]]s&amp;#039;&amp;#039;&amp;#039; for compaction and efficiency.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l180&quot;&gt;Строка 180:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 184:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scripting Tutorials]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scripting Tutorials]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[de:Komprimieren]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=1658&amp;oldid=prev</id>
		<title>Patarakin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=1658&amp;oldid=prev"/>
		<updated>2022-07-21T08:33:13Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:33, 21 июля 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=1657&amp;oldid=prev</id>
		<title>scratch&gt;TemplatesFTW: Automated edit: fixed 1 style guideline</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Improving_Scripts&amp;diff=1657&amp;oldid=prev"/>
		<updated>2020-05-25T08:17:10Z</updated>

		<summary type="html">&lt;p&gt;Automated edit: fixed 1 style guideline&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article explains methods of &amp;#039;&amp;#039;&amp;#039;improving [[script]]s&amp;#039;&amp;#039;&amp;#039; for compaction and efficiency.&lt;br /&gt;
&lt;br /&gt;
==Reasons to Keep Scripts Compact and Efficient==&lt;br /&gt;
&lt;br /&gt;
Besides improving your scripts being a professional practice, some reasons why one should compact and further work on scripts include:&lt;br /&gt;
&lt;br /&gt;
* To reduce [[project]] slowness due to cluttered or inefficient scripts&lt;br /&gt;
* To make them easier to handle, so you can easily change something without having to change many scripts, and so people can make [[remix]]es easier, by simply changing the pattern.&lt;br /&gt;
&lt;br /&gt;
For example, using the methods stated later in this tutorial, this long, cluttered script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
set [upgrade v] to [0]&lt;br /&gt;
set [cost v] to [5]&lt;br /&gt;
forever&lt;br /&gt;
  wait until &amp;lt;&amp;lt;mouse down?&amp;gt; and &amp;lt;touching [mouse pointer v]?&amp;gt;&amp;gt;&lt;br /&gt;
    if &amp;lt;(upgrade) = [0]&amp;gt; then&lt;br /&gt;
      change [attack v] by (10)&lt;br /&gt;
      set [cost v] to [8]&lt;br /&gt;
      change [upgrade v] by (1)&lt;br /&gt;
      switch costume to [costume2 v]&lt;br /&gt;
    end&lt;br /&gt;
    if &amp;lt;(upgrade) = [1]&amp;gt; then //and so on until upgrade = 10&lt;br /&gt;
     change [attack v] by (20)&lt;br /&gt;
     set [cost v] to [12]&lt;br /&gt;
     change [upgrade v] by (1)&lt;br /&gt;
     switch costume to [costume3 v]&lt;br /&gt;
   end&lt;br /&gt;
wait until &amp;lt;not &amp;lt;mouse down?&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...can be transformed into this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
set [upgrade v] to [0]&lt;br /&gt;
set [cost v] to [5]&lt;br /&gt;
forever&lt;br /&gt;
  if &amp;lt;&amp;lt;mouse down?&amp;gt; and &amp;lt;touching [mouse pointer v]?&amp;gt;&amp;gt; then&lt;br /&gt;
    if &amp;lt;(upgrade) &amp;lt; [11]&amp;gt; then&lt;br /&gt;
      change [attack v] by (((upgrades) + (1)) * (10))&lt;br /&gt;
      set [cost v] to (round ((cost) * (1.1)))&lt;br /&gt;
      change [upgrade v] by (1)&lt;br /&gt;
      next costume&lt;br /&gt;
    else&lt;br /&gt;
      say [Sorry, this upgrade is maxed out.]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though this is a very simple example, this is often all you need, whereas the previous script would have 10 if statements in it.&lt;br /&gt;
&lt;br /&gt;
As you can see, handling the second one would be much easier.&lt;br /&gt;
&lt;br /&gt;
==How to do it==&lt;br /&gt;
&lt;br /&gt;
There are two main things to look for in inefficient scripts:&lt;br /&gt;
# Scripts that can be combined&lt;br /&gt;
# Patterns with numbers that can be made into loops&lt;br /&gt;
&lt;br /&gt;
===Combining Scripts===&lt;br /&gt;
&lt;br /&gt;
You should see if scripts can be ran together.&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s a good example of some scripts that can be combined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
show&lt;br /&gt;
set [HP v] to (100)&lt;br /&gt;
&lt;br /&gt;
when gf clicked&lt;br /&gt;
broadcast [gameStart v]&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you probably can see, they can easily be combined. There are much more complex instances of such, but this should make the point clear.&lt;br /&gt;
&lt;br /&gt;
The two scripts do not need to be on different [[Hat Blocks|hat blocks]] as they can easily be combined.&lt;br /&gt;
&lt;br /&gt;
Here is a more complex example:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
switch costume to [cat v]&lt;br /&gt;
wait (1) secs&lt;br /&gt;
switch costume to [dog v]&lt;br /&gt;
wait (1) secs&lt;br /&gt;
switch costume to [cat v]&lt;br /&gt;
&lt;br /&gt;
when gf clicked&lt;br /&gt;
say [I am a cat!] for (1) secs&lt;br /&gt;
wait (1) secs&lt;br /&gt;
say [Now I am a dog!] for (1) secs&lt;br /&gt;
wait (1) secs&lt;br /&gt;
say [And now I am a cat again!]&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The pauses within the scripts is constant and lines up. Therefore, the following combination is possible:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
switch costume to [cat v]&lt;br /&gt;
say [I am a cat!] for (1) secs&lt;br /&gt;
wait (1) secs&lt;br /&gt;
switch costume to [dog v]&lt;br /&gt;
say [Now I am a dog!] for (2) secs&lt;br /&gt;
wait (1) secs&lt;br /&gt;
switch costume to [cat v]&lt;br /&gt;
say [And now I am a cat again!]&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, some scripts with the same hat block cannot be combined, like these:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
broadcast [start game v] and wait&lt;br /&gt;
broadcast [calculate score v] and wait&lt;br /&gt;
&lt;br /&gt;
when gf clicked&lt;br /&gt;
forever&lt;br /&gt;
  play sound [background music v] until done&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
The pauses that the blocks make do not line up, and one is in a loop while the other is not.&lt;br /&gt;
&lt;br /&gt;
===Finding Patterns===&lt;br /&gt;
&lt;br /&gt;
This is a bit more tricky. See the scripts for [[projects:10735439|this]] project&amp;#039;s shop buttons for a more complex example.&lt;br /&gt;
&lt;br /&gt;
For a simpler example, we will use a script shown previously:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
set [upgrade v] to [0]&lt;br /&gt;
set [cost v] to [5]&lt;br /&gt;
forever&lt;br /&gt;
  wait until &amp;lt;&amp;lt;mouse down?&amp;gt; and &amp;lt;touching [mouse pointer v]?&amp;gt;&amp;gt;&lt;br /&gt;
    if &amp;lt;(upgrade) = [0]&amp;gt; then&lt;br /&gt;
      change [attack v] by (10)&lt;br /&gt;
      set [cost v] to [8]&lt;br /&gt;
      change [upgrade v] by (1)&lt;br /&gt;
      switch costume to [costume2 v]&lt;br /&gt;
    end&lt;br /&gt;
    if &amp;lt;(upgrade) = [1]&amp;gt; then //and so on until upgrade = 10&lt;br /&gt;
     change [attack v] by (20)&lt;br /&gt;
     set [cost v] to [12]&lt;br /&gt;
     change [upgrade v] by (1)&lt;br /&gt;
     switch costume to [costume3 v]&lt;br /&gt;
   end&lt;br /&gt;
wait until &amp;lt;not &amp;lt;mouse down?&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where&amp;#039;s the pattern? Well, we know a few things that can give us clues on what script to make:&lt;br /&gt;
* There are ten upgrades, and therefore, ten costumes (assuming each upgrade changes the button&amp;#039;s appearance).&lt;br /&gt;
* The attack so far is being upgraded by ten more each time. Therefore, you can assume that the attack will be upgraded in the same way up until upgrade equals 10, unless you prefer different results.&lt;br /&gt;
* The costumes are organized in order, and therefore, the upgrade number can correspond to them. Even better, the [[Next Costume]] block can be used.&lt;br /&gt;
* The cost is changed by the rounded number of the previous number times 1.5. (1.5×5≈8; 1.5×8≈12)&lt;br /&gt;
&lt;br /&gt;
From these clues, this script can be made:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
set [upgrade v] to [0]&lt;br /&gt;
set [cost v] to [5]&lt;br /&gt;
forever&lt;br /&gt;
 wait until &amp;lt;&amp;lt;mouse down?&amp;gt; and &amp;lt;touching [mouse pointer v]?&amp;gt;&amp;gt;&lt;br /&gt;
    if &amp;lt;(upgrade) &amp;lt; [11]&amp;gt; then&lt;br /&gt;
      change [attack v] by (((upgrades) + (1)) * (10))&lt;br /&gt;
      set [cost v] to (round ((cost) * (1.5)))&lt;br /&gt;
      change [upgrade v] by (1)&lt;br /&gt;
      next costume&lt;br /&gt;
    else&lt;br /&gt;
      say [Sorry, this upgrade is maxed out.]&lt;br /&gt;
    end&lt;br /&gt;
wait until &amp;lt;not &amp;lt;mouse down?&amp;gt;&amp;gt;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tip==&lt;br /&gt;
&lt;br /&gt;
Improving your scripts is something that should be done, but it is much easier to improve and find patterns in scripts &amp;#039;&amp;#039;after&amp;#039;&amp;#039; you have made them. Make your scripts so that they do what you want them to do, &amp;#039;&amp;#039;then&amp;#039;&amp;#039; improve them, unless you already have efficient scripts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;br /&gt;
[[de:Komprimieren]]&lt;/div&gt;</summary>
		<author><name>scratch&gt;TemplatesFTW</name></author>
	</entry>
</feed>