Conditional compilation with haxedef if=


#1

Why does the following not work?

project.xml:

<haxedef name="WAV" if="android||flash" />
<assets path="Assets/snd" rename="assets/snd" type="audio" include="*.WAV" if="WAV" />
<assets path="Assets/snd" rename="assets/snd" type="audio" include="*.ogg" unless="WAV" />

code:

  public static var snd_COIN: Sound = null;
#if WAV
    snd_COIN = Assets.getSound ("assets/snd/COIN.WAV");
#else
    snd_COIN = Assets.getSound ("assets/snd/COIN.ogg");
#end
  ...
  snd_COIN.play ();

When I compile for flash, it says: Warning: Skipping unsupported OGG file “Assets/snd/COIN.ogg” and then [Assets] There is no audio asset with an ID of “assets/snd/COIN.WAV” and then can’t play the sound.
If I add -DWAV to the command line it works fine.


#2

Try <set />

Using -D on the command-line is equivalent to both set and haxedef, perhaps we should consider a change in this behavior in the future

A “set” value affects project parsing, a haxedef is passed to the Haxe compile process :slight_smile:


#3

I need to write conditional statement within project.xml in order to use correct android icon based on a flag value, but below approach doesn’t work in current haxe flixel.

		<icon path="devicon.svg" if="!ADMOBPROD" />
		<icon path="prodicon.svg" if="ADMOBPROD"  />

#4

Hi, not sure you can use “!” here : I think that’s what “unless” is for

<icon path="devicon.svg" unless="ADMOBPROD" />

#5

@Maste,

I also need it work with prodicon.svg as well. I need to pick one of two icons to compile based on a flag.
I wanted to display a different android icon to show if it’s an dev/prod version.


#6

Sorry I only wrote the part that I think needs to be changed, the whole thing should look like

<icon path="devicon.svg" unless="ADMOBPROD" />
<icon path="prodicon.svg" if="ADMOBPROD"  />

didn’t test but should work I think ?