Strange problem using #define [SOLVED]

Started by Joe, Wed 29/04/2009 15:05:55

Previous topic - Next topic

Joe

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 '+'

Code: ags

#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.
Copinstar © Oficial Site

Gilbert

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.

SMF spam blocked by CleanTalk