How To

Can I use it?

0

japanese 2020-02-28 09:35

I want use about this

IF 1<TX<24

but it is not move. so I change it to this

IF 1<TX AND TX<24
Then it is move.
I can't use the first one?
I am sorry that my English is so bad.


was8bit 2020-02-28 11:36 (Edited)

It is not documented that NX can specifically handle this, but it should work sometimes...

Mathematically, NX converts logic into True (-1) or False (0) so try this code...

TX=5
PRINT 1<TX<24
PRINT 1<TX
PRINT -1<24
IF 1<TX<24 THEN PRINT "YES"

So, it is converting the logic comparisons into -1 which NX's way of saying TRUE


was8bit 2020-02-28 11:42 (Edited)

Try this code..

TX=-10
PRINT -20<TX<-5

Yields 0 or FALSE because

-20<TX yields -1 or TRUE
BUT -1<-5 yields 0 or FALSE


... so NO NX does not directly handle the format A<B<C ... BUT if you understand how NX converts each logic part into a -1 or a 0 you can make it work sometimes :)


was8bit 2020-02-28 11:46 (Edited)

For best practice, i would recommend your approach

IF MIN<X AND X<MAX THEN

That way you know it will always work OK :)

TX=-10
PRINT -20<TX<-5
PRINT -20<TX AND TX<-5


was8bit 2020-02-28 11:50

Using PRINT to print out a math result is a great way to test exactly WHAT NX sees when it is processing LOGIC statements...

-1 is TRUE
0 is FALSE

So using the PRINT trick lets you directly see what NX sees and can help you debug and fix something that is not doing what you want it to do :)


japanese 2020-02-28 13:34

ok
thank you :)


was8bit 2020-02-28 16:32

:)


japanese 2020-03-12 02:15

I understand what you are saying
But this is no work

Unnamed Program.nx | Open in app
2020-03-12 02:15

was8bit 2020-03-12 02:41 (Edited)

This is because variables inside a sub exist only inside the sub, even if the variable name is the same inside the sub and outside the sub, the variables are different.. unless you declare the variable as GLOBAL... otherwise you must pass values to the sub... i have both fixes for you :)

Fix 1.nx | Open in app
2020-03-12 02:41

was8bit 2020-03-12 02:42

Fix 2

Fix 2.nx | Open in app
2020-03-12 02:42

was8bit 2020-03-12 02:45

You will need to enable the DEBUG mode to see the TRACE .... while program is running, tap the top right corner and enable DEBUG mode, then test :)


was8bit 2020-03-12 03:05

Also, check this out as a good demo for SUB

https://lowresnx.inutilis.com/topic.php?id=1064


Log in to reply.