• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Nested static ifs are annoying!

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
Well, I think the title fits very well.
In the last hours I wrote a system for my own and it turned out that I got 4 nested static ifs. Now, since two of them are partially disabled normaly, JassHelper sees them as comments and ignores them for syntax-checking.
Enabling all doesn't help, since most of them have an "Else"-part.
Checking for errors each time (I got them nested quite often^^) I'd have to check all combinations of "true" and "false" for these booleans.
Is there anything to avoid this problem?

Greets, Justify.
 
Level 13
Joined
Mar 16, 2008
Messages
941
Uuh, my solution would be to not use static ifs.
Would need to change the script anytime I find a bug or want to change something. I know (I've to admit that I didn't think of this option before) that this would be possible, but I hoped to find a better solution (depending on the code this can get realy annoying). Maybe like I always do, never had a serios question here for months :p Like maybe an option I didn't see in JNGP or something :D
No cJass! no Zinc! :p I like vJass and love the syntax.
Do I have to code completly in cJass to use defines?
+, Where is it involved? Heard about it often and never thought of it.

EDIT: Could it be, Poot, that you don't like me? :p Whenever I post I get such an answer from you :O (so bad ironic)
 
Level 9
Joined
Nov 28, 2008
Messages
704
http://cjass.xgm.ru/

You would just use it normally. You dont need to change *any* syntax you have (it's perfectly compatible with normal vJass), you would just use #if and #endif.

JASS:
#if DEBUG //Debug is a defined macro that is set to 1 when you check "debug mode" in JassHelpers menu.
    call BJDebugMsg("Roar!")
#endif

JASS:
#define COLOR = RED
#if COLOR == RED
    call BJDebugMsg("Roar!")
#endif

cJass Manual said:
cJass syntax introduces useful conditional compilation commands. Using them you can include or exclude specified blocks of code during map parsing. Controlling elements of this construct can be values, defines or enums (see 5). Their syntax is the following:
#define CONTROL = 3 #if CONTROL == 3 // code #elseif CONTROL == 1 // alternative code #else // more other code #endif

Currently, only == and != comparison operations are supported.

In such conditional blocks you can write any code with one limitation: they shouldn’t contain identical define declarations:
#if 1 != 0 #define msg = "hello!" #else #define msg = "good bye!" #endif

If you try to save this code, parser will throw the define redeclaration error. If you want to use code, similar to above, you should declare the macrodefinition before conditional translation blocks and set its value in those blocks with setdef directive:
#define msg #if 1 != 0 #setdef msg = "hello!" #else #setdef msg = "good bye!" #endif

Condiitonal compilation directives can also be triggered by a state of flag - macrodefinition with a special value.
#define MY_FLAG = true #if MY_FLAG // code #else // alternative code #endif

The #if value directive will work only if the compared macrodefinition has a value of true or 1. You can use the DEBUG predefined macro to write code, which is compiled only in debug mode.

http://cjass.xgm.ru/manual-en#htoc26 is where thats from. I would read it at that link because it's better formatted there.

Dont forget to use #define private inside scopes and libraries or it might have an adverse effect on the rest of your map, though. A #define (you can also just use "define", apparently) will search n replace any symbol it finds that has your define in it (it is smart enough to avoid things like comments and such, of course, and it will not replace things with brackets, .'s and such unless you #define <stufflikethis>).

It's really an easy install. Download, point it to your JNGP directory, and it is done. Oone restart of WE is all thats needed.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Would need to change the script anytime I find a bug or want to change something. I know (I've to admit that I didn't think of this option before) that this would be possible, but I hoped to find a better solution (depending on the code this can get realy annoying). Maybe like I always do, never had a serios question here for months :p Like maybe an option I didn't see in JNGP or something :D
No cJass! no Zinc! :p I like vJass and love the syntax.
Do I have to code completly in cJass to use defines?
+, Where is it involved? Heard about it often and never thought of it.
I just use /**/ or // to get rid of junk I don't need at the moment. /**/ is more flexible than static if anyways.

EDIT: Could it be, Poot, that you don't like me? :p Whenever I post I get such an answer from you :O (so bad ironic)
No, it's just that I don't like many of vJass's more recent features.

--

Mooglefrooglian: cJass is a joke, get over it.
 
Level 13
Joined
Mar 16, 2008
Messages
941
@moogfroog
I thought Justify just explicitly stated that he doesn not want to use cJass or Zinc...
But I asked for a source, just to see it. It's okay, thanks moog and EoW :p

@Purple: I don't know, I like them. For example, my latest system had an option that requires timer, while the rest of it doesn't. Optional TimerUtils and this boolean combined in a static if. I like it, I'm relieved that this isn't personal :p
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
@Purple: I don't know, I like them. For example, my latest system had an option that requires timer, while the rest of it doesn't. Optional TimerUtils and this boolean combined in a static if. I like it, I'm relieved that this isn't personal :p
Eh, I'm pretty openly hostile if it's personal, but more importantly I never get so unless I have a good reason to (I don't just dislike random people).

Anyhow, static ifs and optional libraries just seem like a way to not decide and make it seem like a design decision. It's not like anyone really had trouble without them.
 
Status
Not open for further replies.
Top