BOS Operators???

BOS Operators???

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

BOS Operators???

Post 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 ????.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Code: Select all

d = (a?b:c);

Code: Select all

if (a) d = b;
else d = c;
That's usually the use for the ? operator in C-like languages.

The & operator could have been useful for working with masks indeed.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Oddly enough, I'm pretty sure that | compiles, though that doesn't mean it nessacerily works.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post 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.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post 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.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

| is also used to evaluate multiple flags in sequences, since its a bitwise OR

NOEXPLODE | EXPLODEONHIT etc.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post 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.

Code: Select all

a = 10; a = a + (a>1);
will increase a by 1 since it's true. Not sure about the usefulness though.

edit2:
& does exist, just write it out.
AND, OR, ...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post 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?
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post 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.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post 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.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post 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?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Yep.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post 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?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post 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.
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Post by Peet »

Break ends the function or loop or conditional that it is called in.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post 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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Aaaaah!!! Me wants this to work (and, uh, I hear something like it will in next Spring):

TurnDirection(dir)
{
direction = dir;
}
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post 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 :|
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post 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.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Post 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).
Post Reply

Return to “Game Development”