Page 1 of 1

RE Logic Syntax (The IF statements in console)

PostPosted: 13 Aug 2011, 22:43
by ZeroKnight
Hello, I'm working on my Extended Compass mod and I have a question concerning RE's ... weird logic syntax. For example, taken from Compass.cfg:
{l Code}: {l Select All Code}
if (&& (> (mutators) 0) (& (mutators) 0x0020)) [compass "loadout" [showgui loadout]]

My question is, how on Earth does it work? I'm used to seeing C++ and the like logic, so I've never seen this...and I believe this is unique to RE.

Anyway, what I'm trying to accomplish is a feature that automatically sets a bind, based on game mode. In my case, it's changing the order of compass rotation. But since I have no idea how RE logic works, I can't add it. So my main question is, how do I write it? Like, why are there logical and bitwise AND, and a GT immediately following opening parentheses? I assume it has something to do with the odd order of nesting in it, but even still, looking at it, it doesn't make the least bit of sense. Could a dev that understands please show me the light?

Re: RE Logic Syntax (The IF statements in console)

PostPosted: 14 Aug 2011, 01:10
by srbs
Cube, Cube 2: Sauerbraten, Red Eclipse and all others based on Cube use a language called cubescript. Cubescript uses hungarian & prefix notation.

Hungarian:
In C++, '>' can apply to all numbers.
In cubescript, '>' refers to integers, '>f' refers to floating point numbers, and '>s' if for strings. (based on ascii)

Prefix:
In C++ an if statement would say:
{l Code}: {l Select All Code}
if (1>2)

In cubescript:
{l Code}: {l Select All Code}
if (> 1 2)


Blocks of code are bound by [], while in C++ it's {}.
All commands (unless on their own lines) are surrounded by ().
Commands may be separated by ';' or new lines. (C++ is ';' only)

The if statement you show above can be written like this (in C++'s infix notation):
{l Code}: {l Select All Code}
if ( (mutators > 0) && (mutators & 0x0020) ) { compass "loadout" {showgui loadout} }



The command 'mutators' is a bit-field value to signify each mutator, since there can be more than one.
Obviously, if the mutators' value is 0, there are no mutators applied (hence the >0 part)

The bit-wise & in this case is for identifying the specific mutator. (I don't know which this is though)

I hope that I explained it well, feel free to ask more questions.

srbs

Re: RE Logic Syntax (The IF statements in console)

PostPosted: 15 Aug 2011, 22:57
by ZeroKnight
Ah! That was indeed explained well! I've never heard of (or even seen until now, for that matter) prefix notation. (I'm still pretty new to programming) I see how it works now, thank you, srbs. ^_^ It takes a bit visual jumping around, but I've got it now :D
Thanks much, srbs. I'll report back if I have any more questions.