Discussion Forums at Tactical Neuronics


Re: This piece of code will not work and I can't figure out why From:
Robert Jessop

Probably because its too long and you'll need to cut it down. There is a limit to the length of math statements the game will cope with. My SC III takes five cmath statements to generate a number telling it what to do each click.

You might also be able to simplify it by using boolean operators with AND and OR.

e.g. ((~v1 = ~v2) AND 3) OR ((~v3 > ~v4) AND 7) OR (... more expressions)

This will return 3 if v1 equals v2 or 7 if v3 > v4.

This works because = and > return -1 if true. AND and OR work on every bit of a number, -1 is represented by every bit being one. 3 is 0011 and 7 is 0111 in binary. so ANDing any number with -1 returns that number while ANDing it with 0 (false) gives 0. The ORs mean that whatever number is the highest is the final result. for that to work you need to use numbers that are one less than powers of two (1,3,7,15,31,63...)

You can use variables in gotos:

goto label ~v1

label 3:

label 7:

Er, I meant to write a quick answer because I'm supposed to be doing coursework and I just gave away all the best tips. Nevermind.

P.S. you must have spaces on either side of = and > for then to work properly - i.e. a = b not a=b.

This message is a Reply to: This piece of code will not work and I can't figure out why from jeremiah

Replies to this message:
-None-


© 2001, John A. Reder.