Page 1 of 2
BOS Operators???
Posted: 20 Mar 2007, 13:13
by KDR_11k
I just noticed that BOS has no & (binary and) operator. WHY???
Also I noticed that there's a ? operator. WTF does that do? Same for ??, ??? and ????.
Posted: 20 Mar 2007, 15:27
by rattle
That's usually the use for the ? operator in C-like languages.
The & operator could have been useful for working with masks indeed.
Posted: 20 Mar 2007, 15:36
by FLOZi
Oddly enough, I'm pretty sure that | compiles, though that doesn't mean it nessacerily works.
Posted: 20 Mar 2007, 16:15
by KDR_11k
| works, & doesn't.
So far I use a == a | b to check if b is in a.
I'm not sure if ? works like that, it seems to be a binary operator.
Posted: 20 Mar 2007, 16:35
by rattle
? is a min(x,y) function.
Code: Select all
var i;
i = 10?9;
i is 9.
i = 10?11;
i is 10.
Posted: 20 Mar 2007, 17:59
by Dragon45
| is also used to evaluate multiple flags in sequences, since its a bitwise OR
NOEXPLODE | EXPLODEONHIT etc.
Posted: 20 Mar 2007, 18:20
by rattle
It might be a bitwise AND though, since it's used with explode mostly.
I mean, in "explode right_arm type FALL | FIRE" OR makes little sense.
Okay I tested this.
16|32 is 48.
32|7 is 39.
...
edit:
It's a bitwise & indeed. 32|7|1 is 39, since 0010 0111 includes 0000 0001.
So you can use it for flags. Pretty useless without & though.
The % operator compiles as well, no idea what it does though. It's not the rest operator. ~ does as well, same about it's use. Same for ´, `, ' etc. Apparently some characters do get accepted as operators but do nothing.
Just found out that you can use operators used in if queries anywhere, i.e.
will increase a by 1 since it's true. Not sure about the usefulness though.
edit2:
& does exist, just write it out.
AND, OR, ...
Posted: 20 Mar 2007, 19:40
by FLOZi
presumably AND is &&, and OR is ||, not the same as & and |. I couldn't get % to compile myself, one assumes it is modulus. ~ could be bitwise complement?
Posted: 20 Mar 2007, 20:11
by rattle
Hmm, why's 127 AND 32 true and 128 AND 32 false then?
Apparently the logical operators act as binary operators too... this is confusing.
Posted: 20 Mar 2007, 20:32
by KDR_11k
127 && 32 is 1, though (and I looked through the compiler files, && and AND have the same opcode, as do OR and ||). It compares bitwise but it only returns true or false, not the proper result.
a = a + (a>1);
You sound surprised by some of this stuff.
I mean, in "explode right_arm type FALL | FIRE" OR makes little sense.
Um, read that again. Bitwise OR is the ONLY thing that makes sense.
Posted: 20 Mar 2007, 20:41
by rattle
Um yeah you're right, confused the bitwise OR with the logical OR. Although, in this case it adds the values up bitwise to a mask.
So a proper result would be the partial mask which matched, i.e. 127&32 is 32 while 128&32 is 0?
Posted: 20 Mar 2007, 21:38
by KDR_11k
Yep.
Posted: 21 Mar 2007, 03:44
by Argh
From Compiler.cfg.
I'm an idiot. Didn't know that FOR/NEXT was allowed, among other things.
Code: Select all
[OPERATORS]
Operator = ! ;
Operator = NOT ;
Operator = * ;
Operator = /;
Operator = +;
Operator = -;
Operator = <;
Operator = <=;
Operator= > ;
Operator= >= ;
Operator= >? ;
Operator= >=? ;
Operator= == ;
Operator= != ;
Operator= ? ;
Operator= | ;
Operator= && ;
Operator= AND ;
Operator= || ;
Operator= OR ;
Operator= ?? ;
Operator= ??? ;
Operator= ???? ;
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
[STD_DEFS]
Name = FALSE;
Value = 0;
Name= TRUE;
Value = 1;
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
[COMMANDS]
Keyword = if;
Keyword = @endif;
Keyword = @endelse;
Keyword = for;
Keyword = @next_for_1;
Keyword = @next_for_2;
Keyword = while;
Keyword = @endwhile;
Keyword = break;
Keyword = continue;
Keyword = @NewScript;
Keyword = @PopFVar;
Keyword = @PopSVar;
Keyword = static-var;
Keyword = sound;
Keyword = var;
Keyword = piece;
Keyword = move;
Keyword = turn;
Keyword = spin;
Keyword = return;
Keyword = stop-spin;
Keyword = emit-sfx;
Keyword = sleep;
Keyword = rand;
Keyword = get;
Keyword = set;
Keyword = attach-unit;
Keyword = drop-unit;
Keyword = play-sound;
Keyword = stop-sound;
Keyword = show;
Keyword = hide;
Keyword = cache;
Keyword = dont-cache;
Keyword = dont-shadow;
Keyword = dont-shade;
Keyword = signal;
Keyword = set-signal-mask;
Keyword = wait-for-turn;
Keyword = wait-for-move;
Keyword = explode;
Keyword = Mission-Command;
Keyword = call-script;
Keyword = start-script;
...hey, there's some very interesting stuff here. AND there's some important stuff that's missing. Where's the vertex-moving stuff?
Posted: 21 Mar 2007, 04:10
by Argh
What does Break do? Does it do anything in Spring at all?
Does stop-sound work in Spring? I'm guessing not.
And, look! Mission-Command! If we had a way to hook into that and pass stuff back and forth... tada, ready-made per unit AI.
Posted: 21 Mar 2007, 04:11
by Peet
Break ends the function or loop or conditional that it is called in.
Posted: 21 Mar 2007, 04:23
by Argh
Sooo... can Break stop an aiming function? Cuz that'd be... erm... useful.
And what does @NewScript do?
@PopFVar? @PopSVar? Sounds like they feed values into variables to avoid divide-by-zeroes. Probably just old stuff from Cavedog debugging.
And why @endif, @endelse, @endwhile???
What does for ( ;; ) mean? Does that actually work? Is it an infinite "for" that would be more efficient than a WHILE?
I am realizing there's a bunch of interesting junk in here... how much of it works with Spring is anybody's guess, though.
Posted: 21 Mar 2007, 04:26
by Argh
Aaaaah!!! Me wants this to work (and, uh, I hear something like it will in next Spring):
TurnDirection(dir)
{
direction = dir;
}
Posted: 21 Mar 2007, 04:50
by FLOZi
~ and % aren't in there so I guess they don't do anything...
Wth are >? and >=? for?
break i knew was in, but generally isn't that useful except for killing infinite loops - i doubt it will allow you to kill an aim function, argh, what's wrong with return for that anyway? Likewise, continue isn't of that much use either, merely a shortcut to something you can do with conditionals anwyay.
And why are you always adamant BOS supports vertex moving? I've never seen any evidence for that

Posted: 21 Mar 2007, 07:14
by KDR_11k
The @ stuff looks more like internal codes that are used for establishing the basic grammar.
Argh, if you want to kill an aiming function, aren't signals and returns enough?
A for is just a fancy way of saying while, the differentiation exists so it's clearer that a loop iterates through a number of values.
Posted: 21 Mar 2007, 07:24
by yuritch
Argh wrote:Sooo... can Break stop an aiming function? Cuz that'd be... erm... useful.
Here is what break does, AFAIK:
Code: Select all
i = 0;
j=50;
while(i<100)
{
++i;
if(i==j)
{
break;
}
}
While loop should stop once i reaches 50. I have never used that in actual scripts, though, so I'm not sure it really works, but that's what break does in C-like languages (like BOS).