Use custom IFDEF so same project is full version and lite, is it possible?

Previous topic - Next topic

BdR

The full version of my game is in the appstore and now I want to make a lite version as a sort of advertising. The code will be for the largest part exactly the same as the normal full version. Only a few lines have to change so if possible I'd rather not make a separate GLBasic project, keeping in mind possible bugfixes and code maintenance etc.

I saw in this topic that you can use the ?IFDEF and ?ENDIF as precompiler commands for glbasic. In that topic it is used to determine whether you're compiler for iphone or not.

My question is, can I use ?IFDEF and ?ENDIF to check for a custom ?DEFINE, and if so how does it work? I've tried the code example below but that doesn't seem to work. It always gets to the if-part of the ?IFDEF, regardless of wether or not I disable that first ?DEFINE line it never goes to the else-part.

Code (glbasic) Select
?DEFINE CompileLiteVersion

?IFDEF CompileLiteVersion
  DEBUG "lite version\n"                 // if-part
?ELSE
  DEBUG "This is NOT the lite version\n" // else-part
?ENDIF

MrTAToad

You could have the debug version has the lite one, and then you could check using ?IFDEF GLB_DEBUG

Moru

You can't just disable that line with //, it doesn't care about comment lines or not. You have to delete the whole line or at least separate the ? and define with a space in the comment mabe?

Slydog

This should work:
Code (glbasic) Select
?DEFINE CompileLiteVersion

?IF CompileLiteVersion
  DEBUG "lite version\n"                 // if-part
?ELSE
  DEBUG "This is NOT the lite version\n" // else-part
?ENDIF


That's if the following works, taken from the 'Preprocessor Commands' from the Help file:
Code (glbasic) Select
?IF GLB_VERSION < 7.0
   ?ERROR Precprocessor not enabled ;)
?ENDIF

?IF WIN32
  ?DEFINE FASTGFX
?ENDIF

?IF FASTGFX
   STARTPOLY -1
     POLYVECTOR  0, 0, 0,0, 0xffffff
     POLYVECTOR  0,99, 0,0, 0xffffff
     POLYVECTOR 99,99, 0,0, 0xffffff
   ENDPOLY
?ELSE // slow graphics ->
   DRRAWRECT 0,0,99,99, 0xffffff
?ENDIF
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

BdR

Quote from: Moru on 2011-Jan-24
You can't just disable that line with //, it doesn't care about comment lines or not. You have to delete the whole line or at least separate the ? and define with a space in the comment mabe?

Aha, I was commenting the line, thanks for the tip :good: So to be clear, in the following code the MyDefLite is defined, even though the line is commented out

Code (glbasic) Select
// ?DEFINE MyDefLite

?IFDEF MyDefLite
  DEBUG "code WILL get here\n"
?ENDIF


and in the following MyDefLite is not defined so it never gets to the debug line

Code (glbasic) Select
// ? DEFINE MyDefLite // or delete this line

?IFDEF MyDefLite
  DEBUG "code will NOT get here\n"
?ENDIF


hm, it seems like a bug though.. why does the preprocessor handle a commented line? O_O

hardyx

Commented lines or line parts should be discarted (deleted) by the preprocessor.

You can use "?UNDEF MyDefLite" to disable the variable too.

Kitty Hello

and to be sure the right code is picked, add ?WARNING messages.

BdR

Okay, I finished going through the project and changing small things for the lite version using the ?IFDEFs. :) I just uploaded the app, now waiting for app approval..

BdR

*small kick*

How can I use the ?IFDEF and ?ENDIF commands to recognise if I compile in "Debug Mode" or not (selected in the Compiler menu)? I noticed that the gpc_temp.h file starts with the line "#define WANT_GLB_DEBUGGER 1" when Debug Mode is checked, but I tried the following and it didn't work. With the debugmode checked or unchecked the debug texts never display (compiling in Windows btw).

Code (glbasic) Select
?IFDEF WANT_GLB_DEBUGGER
  DEBUG "code never gets here\n"
?ENDIF

?IFDEF DEBUG
  DEBUG "and code never gets here\n"
?ENDIF

MrTAToad

Code (glbasic) Select
?IFDEF GLB_DEBUG
?WARNING "Using Debug Mode"
?ENDIF


BdR

*major kick* :)

How can I check for combinations of defines? Specifically, I want to make an exception in the lite version for Android, so I want something like ?IF DEFINED(blah) AND NOT DEFINED(boo). I've tried this but it gives an compiler error "syntax error : ... notdefined((1))", see example code below
Code (glbasic) Select

?DEFINE MYDEF_LITE_VERSION
?DEFINE MYDEF_TEST_ANDROID

?IF DEFINED(MYDEF_LITE_VERSION)
  DRAWRECT 80, 80, 80, 80, RGB(255, 0, 0) // lite, red rectangle
  PRINT "test lite", 160, 80
?ENDIF

?IF DEFINED(MYDEF_TEST_ANDROID)
  DRAWRECT 80, 200, 80, 80, RGB(255, 255, 0) // normal, yellow rectangle
  PRINT "test android", 160, 200
?ENDIF

// next line is problem
?IF DEFINED(MYDEF_LITE_VERSION) AND NOT DEFINED(MYDEF_TEST_ANDROID)
  DRAWRECT 80, 320, 80, 80, RGB(255, 0, 255) // lite but not android, purple rectangle
  PRINT "lite, not android", 160, 320
?ENDIF

  SHOWSCREEN
  KEYWAIT


Any ideas?  :doubt:

Slydog

Does this work for you?: (ie. nesting)
Code (glbasic) Select
?IFDEF MYDEF_LITE_VERSION
?IFNDEF MYDEF_TEST_ANDROID
...
?ENDIF
?ENDIF


I only see a 'DEFINED' and no 'NDEFINED' (or similar).
You can 'AND', and 'OR' and such, but you would need a 'NOT' operator too added.

You could reverse your 'MYDEF_TEST_ANDROID' define for the opposite meaning:
Code (glbasic) Select
?DEFINE MYDEF_PRODUCTION_ANDROID  // As opposed to 'MYDEF_TEST_ANDROID'
// Then this should be the equivalent to what your want:
?IF DEFINED(MYDEF_LITE_VERSION) AND DEFINED(MYDEF_PRODUCTION_ANDROID)


You may need to define BOTH for your needs, and change them BOTH to switch modes.
But at least there's a '?IFNDEF' command.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

BdR

I also tried ?IFNDEF blah AND DEFINED(boo) but that didn't give the expected result. And if I combine DEFINED with a nested IFNDEF, it displays the purple rectangle when both MYDEF_LITE_VERSION and MYDEF_TEST_ANDROID are not defined. :blink: that's not right..
Code (glbasic) Select
?IF DEFINED(MYDEF_LITE_VERSION)
  ?IFNDEF MYDEF_TEST_ANDROID
  // lite and not android, purple rectangle
  DRAWRECT 80, 320, 80, 80, RGB(255, 0, 255)
  PRINT "lite, not android", 160, 320
  ?ENDIF
?ENDIF


But I tried nesting and this next bit does what I want :good: thanks
Code (glbasic) Select
?IF DEFINED(MYDEF_LITE_VERSION)
  ?IF DEFINED(MYDEF_TEST_ANDROID)
  // nothing
  ?ELSE
  // lite and not android, purple rectangle
  DRAWRECT 80, 320, 80, 80, RGB(255, 0, 255)
  PRINT "lite, not android", 160, 320
  ?ENDIF
?ENDIF

ampos

why not use a simple IF/THEM?

Code (glbasic) Select
IF demo=0
   debug "Not demo!"
ELSE
  debug "Demo!"
ENDIF


If you want to hide it a little (so it will not cracked), name DEMO to something else as DFWP at the start of your code:

Code (glbasic) Select
DFWP=SQR(4)-1

Notice that game code is not changed by pirates in iOS. They just patch the iOS routines that check validations. If huge games as Infinity Blade has not been altered to get unlimited money, I think your's will not be...
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE