Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Joe on Wed 29/04/2009 15:05:55

Title: Strange problem using #define [SOLVED]
Post by: Joe on Wed 29/04/2009 15:05:55
Hi again AGS users...
When I was trying to make my code more readable using #define an error came UP:

ERROR: Matar.asc(112): Error (line 112): Parse error: invalid use of operator '+'


#define PUNVIC -40
#define PUNPET 400
#define PUNISI  10
#define PUNJOS  30
#define PUNMAE -10

static function Enemigo::Comenzar(int boundX, int jos, int vic, int isi, int mae){

  int PunTot = PUNJOS*jos + PUNVIC*vic + PUNISI*isi + PUNMAE*mae;//THIS IS LINE 112
  //my code
  return PunTot;

}


EDIT: Ok sorry, I solved it, the negative definitions must be in brackets.
Title: Re: Strange problem using #define [SOLVED]
Post by: Gilbert on Wed 29/04/2009 15:27:21
Think of this, what #define actually does is to replace all appearance of the name text in the script into the destination text at compile time.

So, "#define PUNMAE -10" does not actually make a variable with integer value -10. Instead, the compiler scans the script for the appearance of "PUNMAE" and change it into the text "-10".

Therefore, "a = b + PUNMAE;" will just becomes "a = b+ -10", causing the error.