#ifdef NORMAL, HARD
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
#ifdef NORMAL, HARD
It would nice if you could use a comma in this manner to consider NORMAL and HARD difficulties:
Presently, to consider NORMAL and HARD difficulties, one has to do this:
At a glance, it appears that the event only works on EASY, but that's not the case. Sometimes it gets confusing.
Thanks.
#ifdef NORMAL, HARD
Presently, to consider NORMAL and HARD difficulties, one has to do this:
Code: Select all
#ifdef EASY
#else
[event]
name=exit hex
# code
# code
[/event]
#endif
Thanks.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Lord-Knightmare
- Discord Moderator
- Posts: 2359
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: #ifdef NORMAL, HARD
Well, we have this which serves your purpose:
Code: Select all
#ifndef EASY
[event]
name="start"
[/event]
#endif
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: #ifdef NORMAL, HARD
That occasionally creates a mess.
Say, I have 500 lines of code. I want to add 4 lines in the middle that are only applicable to NORMAL and HARD. So now I have to wrap the first 250 lines of code in
I think it would be more elegant, intuitive and tidier to keep one's focus on the code being written as it's written, instead of scrolling up and down, trying to encapsulate previous code as exceptions.
#ifdef
can wreck my tidy code as I try to isolate areas from other areas based on difficulty.Say, I have 500 lines of code. I want to add 4 lines in the middle that are only applicable to NORMAL and HARD. So now I have to wrap the first 250 lines of code in
#ifdef EASY
and the last 250 lines of code in #ifdef EASY
. Ugh. And then later I add another 4 lines that are NORMAL and HARD, and 4 that are EASY and NORMAL. Double ugh.I think it would be more elegant, intuitive and tidier to keep one's focus on the code being written as it's written, instead of scrolling up and down, trying to encapsulate previous code as exceptions.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Lord-Knightmare
- Discord Moderator
- Posts: 2359
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: #ifdef NORMAL, HARD
I deal with like 2000 lines of WML code in my scenarios so this is rather trivial to me. I don't think wrapping the first 250 lines of code inSay, I have 500 lines of code. I want to add 4 lines in the middle that are only applicable to NORMAL and HARD. So now I have to wrap the first 250 lines of code in #ifdef EASY and the last 250 lines of code in #ifdef EASY. Ugh. And then later I add another 4 lines that are NORMAL and HARD, and 4 that are EASY and NORMAL. Double ugh.
#ifdef
and #endif
is necessary. You can pretty much just use #ifndef HARD
for code for Easy and Normal and #ifndef EASY
for NORMAL and HARD.You can avoid the scrolling thing and have a much better experience using a specialised text editor like VSCode with the WML extension installed and enabled.
screenshot
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: #ifdef NORMAL, HARD
#ifdef NORMAL
#define NORMAL_OR_HARD
#enddef
#endif
#ifdef HARD
#define NORMAL_OR_HARD
#enddef
#endif
And then can use #ifdef NORMAL_OR_HARD
#define NORMAL_OR_HARD
#enddef
#endif
#ifdef HARD
#define NORMAL_OR_HARD
#enddef
#endif
And then can use #ifdef NORMAL_OR_HARD
Re: #ifdef NORMAL, HARD
Wow, thanks. It works; I can use #ifdef NORMAL_OR_HARD now. Awesome.
But...now #ifdef NORMAL also includes HARD, even though I don't want it to.
Can you take that awesome code to the next level, so EASY does EASY, NORMAL does NORMAL, HARD does HARD, and NORMAL_OR_HARD does NORMAL and HARD, and EASY_OR_NORMAL does EASY and NORMAL? And make it a macro so I don't have to paste it into every scenario? Or explain how to add it to _main.cfg? Your code boggles my mind; I have no idea how it works. But I like it.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: #ifdef NORMAL, HARD
I really fail to see why it would work why that. Did you actually test this or is it just speculation?
Because this should already work exactly like you described here.Can you take that awesome code to the next level, so EASY does EASY, NORMAL does NORMAL, HARD does HARD, and NORMAL_OR_HARD does NORMAL and HARD, and EASY_OR_NORMAL does EASY and NORMAL?
Just include this above your scenario inclusions in the _main.cfg. It goes right where all your other macro definitions go that you use in your scenarios. Or alternatively just include it to your very first scenario. Not in the others.And make it a macro so I don't have to paste it into every scenario? Or explain how to add it to _main.cfg?
[Sidenote: Definitely do not include this in every scenario - that means in each consecutive scenario you are redefining a symbol without first undefining it (#undef), and wesnoth will dump warnings about this to its log (that's not a nice thing to do ) Yes, if you load up a saved game from scenario 3 after making this addition to scenario 1 will not apply the change to scenario 3, but including it to every scenario is not the way to work this around. ]
A bit of useful reading: https://wiki.wesnoth.org/PreprocessorrefYour code boggles my mind; I have no idea how it works. But I like it.
Ifdef checks if a preprocessor symbol has been defined or not. Ravana's code defines a new symbol in the game, if we're playing on NORMAL, or on HARD. Therefore after that point you can check for this symbol. If it has been defined, then we know we're either on normal on hard, because we only defined it for those cases.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: #ifdef NORMAL, HARD
I tested it. After I read your post, I tested it again -- just in case. In the code, a guy named Jonivan should only appear on NORMAL. But he also appears on HARD.
Code: Select all
#ifdef NORMAL
#define NORMAL_OR_HARD
#enddef
#endif
#ifdef HARD
#define NORMAL_OR_HARD
#enddef
#endif
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#ifdef NORMAL
# # ifdef EASY # Bowman only exists on NORMAL, HARD
# # else
[event] # Bowman regains normal movement
name=exit hex
[filter]
id=Jonivan
x,y=22,4
[/filter]
[event]
name=turn end
[modify_unit]
[filter]
id=Jonivan
[/filter]
max_moves=5
[/modify_unit]
[/event]
[/event]
#endif
Ah, thanks for the info.
Thanks. I guess I just don't see why WML needs to involve preprocessors or symbols. Why didn't the developers make the code like this?WhiteWolf wrote: ↑November 30th, 2020, 7:34 pm A bit of useful reading: https://wiki.wesnoth.org/Preprocessorref
Ifdef checks if a preprocessor symbol has been defined or not. Ravana's code defines a new symbol in the game, if we're playing on NORMAL, or on HARD. Therefore after that point you can check for this symbol. If it has been defined, then we know we're either on normal on hard, because we only defined it for those cases.
Code: Select all
[difficulty]
choice=EASY
[/difficulty]
Code: Select all
[difficulty_limit]
only=normal
only=hard
[difficulty_limit]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: #ifdef NORMAL, HARD
Oops. It's looking like it's my fault the Ravana's code didn't work as expected. I had another #ifdef EASY and #else (which allowed NORMAL and HARD to happen, not EASY) that I forgot about.
See? Those things cause me a headache.
EDIT: It's working now.
Thank you Ravana and WhiteWolf. I like using difficulty levels to add more units, and so forth. That code will help me make fewer mistakes.
I put the code in
See? Those things cause me a headache.
EDIT: It's working now.
Thank you Ravana and WhiteWolf. I like using difficulty levels to add more units, and so forth. That code will help me make fewer mistakes.
I put the code in
[campaign]
in _main.cfg. It didn't stop working, so evidently I guessed right.Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: #ifdef NORMAL, HARD
Preprocessor works even with invalid WML, it is general purpose text inclusion, it does not know anything about WML.Thanks. I guess I just don't see why WML needs to involve preprocessors or symbols. Why didn't the developers make the code like this?
Preprocessor is comfort feature mostly. All WML can be in _main.cfg removing need for inclusions, and difficulty handling can be done with in game choices and variables. I guess historical reasons why it is how it is.
Re: #ifdef NORMAL, HARD
Oh, that was helpful. Thanks. I was wondering if it was something like that.Ravana wrote: ↑November 30th, 2020, 10:24 pm Preprocessor works even with invalid WML, it is general purpose text inclusion, it does not know anything about WML.
Preprocessor is comfort feature mostly. All WML can be in _main.cfg removing need for inclusions, and difficulty handling can be done with in game choices and variables. I guess historical reasons why it is how it is.
I modified your code to include EASY_OR_NORMAL. Man, I like this nifty code. It works so well. It makes sense.
I still think my original suggestion should be considered, though, as it agrees with the K.I.S.S principle espoused by the creator of BfW. Writing EASY to engage the NORMAL and HARD difficulty modes, for example, requires convoluted thinking.
I think some developers are so smart, they don't know or remember what convoluted thinking feels like. WML is easy to them. But for somebody struggling with WML, even a simple problem can be a huge stumbling block. The more logical WML is, imo, the easier it will be to learn and use. And remember.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: #ifdef NORMAL, HARD
I didn't completely understand what you meant by that, so I've read through the original posts too again, and I must ask: did you perhaps miss the tiny extra "n" in Lord-Knightmare's suggestion?
#ifdef X
is an abbreviation for "if [X] is defined"#ifndef X
stands for "if [X] is NOT defined".It's just a negation, which is all over in conditions in programming. It's not a super-long chain of conditions that's impossible to see through.
So you're not writing EASY to engage normal and hard. (Yeah, that would indeed be counter-intuitive). No, instead you write NOT EASY, which means to engage "all other difficulties". That would include nightmare too if your addon has 4 difficulties. (and any custom ones too if that's the case). So if you want to be as general as possible, and want to restrict it to just normal and hard by all means, make sure nightmare doesn't get into it if your code gets into such a context, then indeed Ravana's code is the one to use.
But in your example, you had 500 lines of code, wanted to include 4 in the middle, that's just:
Code: Select all
first 250 lines
#ifndef EASY
4 lines
#endif
other 250 lines
Anyway, I don't think a comma separated list can be implemented in preprocessors. I'm not an expert, but their point is being simple - they're sooo simple that I doubt they could handle something as complex as a comma separated list.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: #ifdef NORMAL, HARD
GASP!
GASP!
GASP!WhiteWolf wrote: ↑December 1st, 2020, 9:57 am So you're not writing EASY to engage normal and hard. (Yeah, that would indeed be counter-intuitive). No, instead you write NOT EASY, which means to engage "all other difficulties"....
There's no need to wrap the first and second 250 lines in an #ifdef. That's the whole point.
Your suspicion was correct, WhiteWolf. I totally didn't see that tiny little "n" in Lord-Knightmare's post. And had I seen it, I probably would've thought it was a typo.
So...um...nevermind!
Thanks for explaining. Also, thanks for contemplating my problem and solving the subtle mystery at the heart of my confusion.
PS: I'm still going to use Ravana's solution. Check-out this beautiful crystal-clear code...
Code: Select all
#ifdef EASY
type=Naga Warrior
#endif
#ifdef NORMAL_OR_HARD
type=Naga Sicarius
#endif
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: #ifdef NORMAL, HARD
Specifically, the preprocessor is a feature found in the C (and C++) programming language. The Wesnoth preprocessor is very similar in design and syntax to the C/C++ preprocessor. Presumably it was made that way so that C/C++ programmers would find it very familiar and easy to use. Of course, for people who aren't C/C++ programmers, the preprocessor may not make very much sense - why does it have this strange syntax that looks nothing like the rest of WML? As Ravana says above, it looks like that mostly for historical reasons.
Re: #ifdef NORMAL, HARD
Oh. Thanks for the explanation. Like you had guessed, I had been thinking, "Why does this code look nothing like the rest of WML?"gnombat wrote: ↑December 1st, 2020, 1:28 pm Specifically, the preprocessor is a feature found in the C (and C++) programming language. The Wesnoth preprocessor is very similar in design and syntax to the C/C++ preprocessor. Presumably it was made that way so that C/C++ programmers would find it very familiar and easy to use. Of course, for people who aren't C/C++ programmers, the preprocessor may not make very much sense - why does it have this strange syntax that looks nothing like the rest of WML? As Ravana says above, it looks like that mostly for historical reasons.
I tried to teach myself C++ once. It went about as well as teaching myself Russian.
Thankfully, WML uses a lot of "words."
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.