<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Stuart&#039;s Pixel Games]]></provider_name><provider_url><![CDATA[http://stuartspixelgames.com]]></provider_url><author_name><![CDATA[SPG]]></author_name><author_url><![CDATA[https://stuartspixelgames.com/author/stuie89/]]></author_url><title><![CDATA[How To Use The Action Command &#8211;&nbsp;PuzzleScript]]></title><type><![CDATA[link]]></type><html><![CDATA[<div class="wp-block-image">
<figure class="aligncenter size-large"><a href="https://www.humblebundle.com/g/puzzledorf"><img data-attachment-id="7638" data-permalink="https://stuartspixelgames.com/wide-ad/" data-orig-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png" data-orig-size="1920,586" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="wide-ad" data-image-description="" data-image-caption="" data-medium-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=300" data-large-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1024" src="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=736" alt="" class="wp-image-7638" srcset="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=736 736w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1472 1472w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=150 150w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=300 300w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=768 768w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1024 1024w" sizes="(max-width: 736px) 100vw, 736px" /></a></figure></div>


<p>This post is part of a series in learning how to make games with PuzzleScript. If you haven’t read my previous tutorials, I recommend you do so <a href="https://stuartspixelgames.com/puzzle-script-tutorials/"><strong>here</strong></a>, as that is assumed knowledge for this post.</p>



<h2 id="the-action-command">The Action Command</h2>



<p>By now we know how to walk around, push and pull blocks, but what if we wanted something to only occur when we press a specific key like&nbsp;<strong>spacebar?</strong></p>



<p>PuzzleScript is a bit limited in what it allows for input, mainly being the arrow keys, Z for Undo, R for Restart, and we can&#8217;t change those, but it does also give us an extra key for <strong>Actions</strong> &#8211; either pressing&nbsp;<strong>spacebar&nbsp;</strong>or the&nbsp;<strong>X&nbsp;</strong>key.</p>



<p>I experimented with this a bit for <strong><a href="https://www.humblebundle.com/g/puzzledorf">Puzzledorf</a></strong>, for example, walking up to bombs and pressing a button to make them explode, but didn&#8217;t end up using it for that project. It can, however, make for some interesting gameplay for other projects.</p>



<p>Using the <strong>Action</strong> command follows a similar format to before. We&#8217;re used to the basic format of PuzzleScript coding:</p>



<pre class="wp-block-preformatted">[ Condition ] -&gt; [ Event ]</pre>



<p>If the condition is true, we do the event. We use the&nbsp;<strong>action&nbsp;</strong>command the same way, but it has it&#8217;s own rules. It looks like this:</p>



<pre class="wp-block-preformatted">[ <strong>Action</strong> <em>Extra Conditions</em> ] -&gt; [ <em>Event</em> ]</pre>



<p>An example of using the Action command would be this:</p>



<pre class="wp-block-preformatted">[ <strong>Action</strong> <em>Player</em> ] -&gt; [ <em>Crate</em> ]</pre>



<p>First,&nbsp;<strong>Action</strong> is always the first word you must put in the condition.</p>



<p>Second, if you want to affect a specific object in the game, you must mention that object in both the condition and the event ( if you mention a different object, it will delete the original and replace it, or mentioning no object will simply remove it).</p>



<p>Finally, you only have to mention the word&nbsp;<strong>Action</strong> in the <b>Condition,&nbsp;</b>however, there are times you might want to mention it in the condition and the event, which I&#8217;ll go into.</p>



<p>Try the above code in a game project. You can start with this <a href="https://www.puzzlescript.net/editor.html?hack=98654baade7a809ec2d829ddd1678258"><strong>sample one</strong>.</a> You will see that what happens is, when you press <strong>spacebar</strong> or <strong>x</strong>, the player object becomes a crate.</p>



<p>The condition is saying, [&nbsp;<strong>If you press the Action key</strong>&nbsp;<em>and if there is a Player object in the level&nbsp;</em>] -&gt; then [ <em>replace the</em>&nbsp;<em>player object with a crate ]</em></p>



<p>Now in your sample project, try the following code:</p>



<pre class="wp-block-preformatted">[ <strong>Action</strong> Player | Crate ] -&gt; [ Player | &gt; Crate ]</pre>



<figure class="wp-block-image"><img data-attachment-id="4476" data-permalink="https://stuartspixelgames.com/2018/07/25/how-to-use-the-action-command-puzzlescript/action-btn-2/" data-orig-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-2.gif" data-orig-size="515,301" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Action Btn 2" data-image-description="" data-image-caption="" data-medium-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-2.gif?w=300" data-large-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-2.gif?w=515" src="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-2.gif" alt="Action Btn 2" class="wp-image-4476" /></figure>



<p>Make sure you&#8217;re surrounded by crates as in the above image. You&#8217;ll notice that it only affects one crate at a time. I&#8217;m not sure what the reason is, but if you want to affect multiple objects with the&nbsp;<strong>Action</strong> command, you need to put it in both the condition and the event.</p>



<p>Replace the code with this updated version:</p>



<pre class="wp-block-preformatted">[ <strong>Action</strong> Player | Crate ] -&gt; [ <strong>Action</strong> Player | &gt; Crate ]</pre>



<figure class="wp-block-image"><img data-attachment-id="4478" data-permalink="https://stuartspixelgames.com/2018/07/25/how-to-use-the-action-command-puzzlescript/action-btn-1/" data-orig-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-11.gif" data-orig-size="515,301" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Action Btn 1" data-image-description="" data-image-caption="" data-medium-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-11.gif?w=300" data-large-file="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-11.gif?w=515" src="https://stuartspixelgames.files.wordpress.com/2018/07/action-btn-11.gif" alt="Action Btn 1" class="wp-image-4478" /></figure>



<p>Now you&#8217;ll see that&nbsp; you push all of the crates at once. If you need to apply the action to multiple objects, make sure you put&nbsp;<strong>Action</strong> in both the condition and the event.</p>



<p>The next tutorial is on <strong><a href="https://stuartspixelgames.com/2016/06/05/checking-multiple-conditions-in-puzzle-script/">How To Check For Multiple Conditions</a>.</strong></p>



<h1 class="has-text-align-center" id="next-tutorial"><strong><a href="https://stuartspixelgames.com/2016/06/05/checking-multiple-conditions-in-puzzle-script/">Next Tutorial &gt;</a></strong></h1>



<div class="is-layout-flow wp-block-group"><div class="wp-block-group__inner-container">
<p class="has-text-align-center has-medium-font-size"><strong>If you enjoyed reading, try my game <a href="https://www.humblebundle.com/g/puzzledorf">Puzzledorf</a>.</strong></p>
</div></div>


<div class="wp-block-image">
<figure class="aligncenter size-large"><a href="https://www.humblebundle.com/g/puzzledorf"><img data-attachment-id="7638" data-permalink="https://stuartspixelgames.com/wide-ad/" data-orig-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png" data-orig-size="1920,586" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="wide-ad" data-image-description="" data-image-caption="" data-medium-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=300" data-large-file="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1024" src="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=736" alt="" class="wp-image-7638" srcset="https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=736 736w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1472 1472w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=150 150w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=300 300w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=768 768w, https://stuartspixelgames.files.wordpress.com/2022/04/wide-ad.png?w=1024 1024w" sizes="(max-width: 736px) 100vw, 736px" /></a></figure></div>]]></html><thumbnail_url><![CDATA[https://stuartspixelgames.files.wordpress.com/2018/07/learnpuzzlescript.png?fit=440%2C330]]></thumbnail_url><thumbnail_width><![CDATA[439]]></thumbnail_width><thumbnail_height><![CDATA[270]]></thumbnail_height></oembed>