xmoonproductions.org
https://www.xmoonproductions.org/

#if condition
https://www.xmoonproductions.org/viewtopic.php?f=28&t=5095
Page 1 of 1

Author:  enkephalin07 [ Mon May 22, 2017 9:04 pm ]
Post subject:  #if condition

This preprocessor condition doesn't throw any errors on compile or runtime:

Code:
#if (PC == "fast")  // PC #defined in initial _init.dat
#include "FASTPATH/objects/objects.dat"
#else
#include "STORYPATH/objects/objects.dat"

However, nothing after the #if seems to be checked. Is there a different format for it, or is implementation not complete yet?

Author:  Eskarn [ Tue May 23, 2017 1:14 am ]
Post subject:  Re: #if condition

XPAdmin would have to confirm but i don't that that would work
Best way would to just have both or only use one set (since they have all the tasks)
Unless you are trying to merge the story and fast together and i don't think that is possible

Author:  enkephalin07 [ Tue May 23, 2017 1:52 am ]
Post subject:  Re: #if condition

Why wouldn't it be possible? The majority of tentacle dreams and dungeon packs is duplicated scripts, and any variants can be conditionally included. Could also merge all character types' storylines in the same way.

I guess I could use the regular conditional, or case, but the point of using a preprocessor directive is to cut down runtime processing and memory.

Author:  Eskarn [ Tue May 23, 2017 6:11 am ]
Post subject:  Re: #if condition

I'm not to sure what you are trying to do

The packs only uses the stuff in that pack as specified in the story.txt
Code:
    code = "init/stories/dungeon/init_monsai.dat"; 

Author:  enkephalin07 [ Tue May 23, 2017 9:20 am ]
Post subject:  Re: #if condition

The code is actually:

Code:
#define STORYSSET "stat_monsai.dat"


The distinction is important because you can use #defines to do elegant scripting like this:

Code:
#include "init/stories/dungeon/settings/STORYSSET"


That's equivalent to a case statement resolved at compile time. If I have PC defined in init_*.dat as "fast", "nerd", "old", "pretty" or "fat", then later I name files and folders to those and have the correct ones for the episode load.

Right now I'm just organizing for easy workflow later, and browsing scripts. Most of my pack files actually point to files in other packs.

Author:  riftporn [ Tue May 23, 2017 5:21 pm ]
Post subject:  Re: #if condition

My C*/Preprocessor knowledge is rusty, but if this works as in C wouldn't you need a #endif? That should throw an error though I believe.

Author:  enkephalin07 [ Tue May 23, 2017 11:22 pm ]
Post subject:  Re: #if condition

You're correct, it does throw an error without an #endif, and in my actual script that came after many more #includes. With that at the end it doesn't throw any errors, but it also doesn't appear to evaluate the #if condition.

Does it not work with strings?

EDIT: That was the reason; it'll only evaluate integers and single chars.

Author:  riftporn [ Wed May 24, 2017 4:34 pm ]
Post subject:  Re: #if condition

Yeah lol. C and strings.

You could maybe use something like this to make it more sane:

Code:
#define PC_FAST 1
#define PC_NERD 2

#define PC PC_FAST

#if PC PC_FAST
  #define.....
#elsif PC PC_NERD
  #define.....
#endif

Author:  enkephalin07 [ Wed May 24, 2017 6:57 pm ]
Post subject:  Re: #if condition

Yeah, I thought of that, but after further testing I found that it's just broken, no matter what I put after #if it never resolves as true.

#ifdef and #ifndef still work, so I'll have to use those.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/