If... or... but with a twist

Is it possible somehow to...

make an if or statement where the variable its comparing to is plus 10 or negative 10, ie

<code><pre><font size=2 face='Courier'>if b1 &lt;= (b12 - 10) or b1 &gt;= (b12 +10) then ... </font></pre></code>

the command goes to ... if the value for b1, say 100 falls not between b12, say 200, does not fall between 190 and 210.

or would i need to use 2 registers to save the b12 - 10 and b12 +10 values.

thanks for any help

nat poate
as i need to use all the other registers and only have b12 left.
 

inglewoodpete

Senior Member
You can't do your mathematics in the IF command. The IF statement can only handle simple comparisons. (Eg If A = B and C &gt; D Then)

Have a look at page 34 of the command manual. I seem to remember that this was described in detail somewhere else in the manual(?)
 
okies, it was just a hope, i think i have arranged my code now so that i can use some other registers, lets hope it still works! wooo

thanks anyways.

ps close, twas 27 and 28 :D

nat poate
 

tarzan

Senior Member
On Picaxes&#8217; that support infrain, infrain2 or keyin, will give you an extra variable if not in use.

Namely: Infra/Keyvalue

Except 08M which uses B13 for Infrain2.

08M infra = another term for variable b13, used within the 08M infrain2 command
18 18A 18X 28A 28X 40X infra = a separate variable used within the infrain command
keyvalue = another name for infra, used within the keyin command

Edited by - tarzan on 07/02/2007 04:15:03
 

demonicpicaxeguy

Senior Member
if b1 &lt;= (b12 - 10) or b1 &gt;= (b12 +10) then


below should work unless you have no more variables left

let b11 = b12 - 10
if b1 &lt;= b11 then goto examplesub1
let b11 = b12 + 10
if b1 &gt;= b11 then goto examplesub2

 

Jeremy Leach

Senior Member
Just for general interest since it looks like you've solved the problem, here's (untested) code that just might help, but needs a bit of explaining!...

<code><pre><font size=2 face='Courier'>
b1 = b1 - 10 MIN b12 - b12 MAX 1 XOR 1 * b1 + 10 Max 12
If b1 &lt; b12 then Goto OutsideRange
</font></pre></code>

Explaining the calculation in sections...
A: <i> b1 - 10 MIN b12 </i>
If b1 is greater than (b12 + 10) then the result of this expression will be &gt;b12

B: <i> - b12 MAX 1 </i>
This will then transform the result to 0 or 1. 1 means b1 &gt;(b12 + 10) and 0 means b1 &lt;= (b12 + 10).

C: <i>XOR 1 </i>
This reverses the meaning of the 1 and 0, so now 0 means b1 &gt;(b12 + 10) and 1 means b1 &lt;= (b12 + 10).

D: <i>* b1 </i>
This gives a lead in to the final calculation. If b1 &gt;(b12 + 10) then it will give 0, and if b1 &lt;= (b12 + 10) it will give b1.

E: <i> + 10 Max 12 </i>
This is the opposite of the first part of the calculation, shown in A, and testing for if b1 &lt; (b12 - 10). However because of step D it also is a final test for if B1 is outside the ranges. If the final result &lt;b12 then it is outside.

I think !
 
Top