{"id":886,"date":"2026-02-13T09:06:26","date_gmt":"2026-02-13T01:06:26","guid":{"rendered":"https:\/\/edu.circuspi.com\/?p=886"},"modified":"2026-03-09T15:46:14","modified_gmt":"2026-03-09T07:46:14","slug":"7-2-how-to-use-variables","status":"publish","type":"post","link":"https:\/\/edu.circuspi.com\/index.php\/gamebit-en\/7-2-how-to-use-variables\/","title":{"rendered":"7.2 How to Use Variables"},"content":{"rendered":"\n<p>Let&#8217;s return to the code. During the sprite creation process, we placed our designed sprite into a &#8220;<strong>Variable<\/strong>.&#8221; Just like our understanding of the box metaphor: once the sprite is stored, the data won&#8217;t change unless we modify it.<\/p>\n\n\n\n<p>You can see that this variable has a name. To avoid picking up the wrong &#8220;box&#8221; when passing variables around, we give it a name. By default, the program names it &#8220;<strong>mySprite<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1666\" height=\"644\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_01.png\" alt=\"\" class=\"wp-image-1167\"\/><\/figure>\n\n\n\n<p>We can understand that the variable &#8220;<strong>mySprite<\/strong>&#8221; is equivalent to the &#8220;<strong>Sprite (Orange Dinosaur)<\/strong>.&#8221; So, when we set the position of &#8220;<strong>mySprite<\/strong>&#8221; or use the controller to move &#8220;<strong>mySprite<\/strong>,&#8221; we are effectively controlling the &#8220;<strong>Sprite (Orange Dinosaur)<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1638\" height=\"654\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_02.png\" alt=\"\" class=\"wp-image-1168\"\/><\/figure>\n\n\n\n<p>At this point, quick thinkers might ask: &#8220;Why can&#8217;t I just do this?&#8221; (referring to using the &#8220;create sprite&#8221; block directly in every command).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"264\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_03.png\" alt=\"\" class=\"wp-image-1169\"\/><\/figure>\n\n\n\n<p>If you write the code as shown in the hypothetical image above, running it will reveal a surprise: there are <strong>two<\/strong> sprites! One is controllable, and the other is not.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1158\" height=\"732\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_04.png\" alt=\"\" class=\"wp-image-1171\"\/><\/figure>\n\n\n\n<p>This is because the block &#8220;<strong>sprite [ ] of kind (Player)<\/strong>&#8221; essentially means &#8220;<strong>Create a NEW Sprite<\/strong>.&#8221; If you use this block again in a movement command, you are creating a second sprite\u2014one positioned at (x: 80, y: 60), and another separate one that moves with the controller. This is why you see a &#8220;shadow clone&#8221; (duplicate) in the <strong>Game Simulator<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"936\" height=\"402\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_05.png\" alt=\"\" class=\"wp-image-1172\"\/><\/figure>\n\n\n\n<p>Although creating a variable seems like an extra step, think of it this way: the named variable is like giving your sprite a specific name. When you want to control it, you call it by its name.<\/p>\n\n\n\n<p>Click on the variable name within the block, and select &#8220;<strong>Rename variable&#8230;<\/strong>&#8221; from the dropdown menu to give it a new name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"829\" height=\"402\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-07-2_06.png\" alt=\"\" class=\"wp-image-1173\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s return to the code. During the sprite creat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":385,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"table_tags":[],"class_list":{"0":"post-886","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-gamebit-en","8":"category-freeinfo-en","9":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/comments?post=886"}],"version-history":[{"count":2,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/886\/revisions"}],"predecessor-version":[{"id":1188,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/886\/revisions\/1188"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media\/385"}],"wp:attachment":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media?parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/categories?post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/tags?post=886"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/table_tags?post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}