Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this is an old question, but I think this point might still be relevant.</p> <p>If you are using the key input to move a character, or shift a value somehow, you are almost always better off avoiding <code>if-then-else</code> statements.</p> <p>The fastest method is usually to do something like this:</p> <pre><code>:getkey -&gt; A :X+(A=24) -&gt; X :X-(A=26) -&gt; X :Y+(A=25) -&gt; Y :Y-(A=34) -&gt; Y </code></pre> <p>which can be further condensed to:</p> <pre><code>:getkey -&gt; A :X+(A=24)-(A=26) -&gt; X :Y+(A=25)-(A=34) -&gt; Y </code></pre> <p>Instead of dealing with the logic through the <code>if</code> statements, we utilize the fact that the <code>(A=24)</code> has a 'boolean' (0 or 1) value. So we add or subtract 1 if it is a certain value.</p> <p>Setting limits is also fairly easy:</p> <pre><code>:getkey -&gt; A :X+(A=26)(X&lt;=20)-(A=24)(X&gt;0) -&gt; X :Y+(A=25)(Y&lt;=15)-(A=34)(Y&gt;=3) -&gt; Y </code></pre> <p>So if <code>(X&lt;20)</code> it will multiply by 1, but when X>=20, <code>(X&lt;20)</code> will multiply by 0, negating the incriment.</p> <p>I use another technique to help with selecting values in some of my programs: The left and right keys increment and decrement a variable by a different value than the up and down keys do. However, it requires some more logic.</p> <pre><code>:getkey -&gt; A :X+10(A=26)(X+10&lt;=100)-10(A=24)(X-10&gt;=0) -&gt; X :Y+(A=25)(Y&lt;15)-(A=34)(Y&gt;3) -&gt; B </code></pre> <p>In this case, the left and right arrows go by tens, and the up and down go by ones. <code>(X+10&lt;=100)</code> is used instead of <code>(X&lt;100)</code> because the latter will be true if <code>X=99</code> so X can go up to 109. The former makes sure that adding ten will not exceed the limit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload