RE Logic Syntax (The IF statements in console)

RE Logic Syntax (The IF statements in console)

Postby ZeroKnight » 13 Aug 2011, 22:43

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?
[ Github ][ WazuClan -- irc.wazuclan.com #wazuclan ][ Zero's Archive of RE Extensions, Scripts, WeapMods & More! ]
User avatar
ZeroKnight
 
Posts: 524
Joined: 08 Jun 2011, 01:24
Location: Ohio, United States

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

Postby srbs » 14 Aug 2011, 01:10

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
srbs
 
Posts: 94
Joined: 17 Mar 2011, 07:00

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

Postby ZeroKnight » 15 Aug 2011, 22:57

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.
[ Github ][ WazuClan -- irc.wazuclan.com #wazuclan ][ Zero's Archive of RE Extensions, Scripts, WeapMods & More! ]
User avatar
ZeroKnight
 
Posts: 524
Joined: 08 Jun 2011, 01:24
Location: Ohio, United States

Who is online

Users browsing this forum: No registered users and 0 guests