Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: mode7 on Sun 13/02/2011 18:11:47

Title: Do I have to import enums? (SOLVED)
Post by: mode7 on Sun 13/02/2011 18:11:47
Hey everybody. Finally got some time to do some coding today. As I'm doing a simple script which gets the keyboard input. It's inside a module and according to keyboard input it sets a enum. My problem is, that the values do work inside the module they get set in but if I want to use the values inside my platformer script/module they don't seem to get updated. I don't get an arror but the keys don't respond either.

Here's the header of the keyboard script:


enum Directions {
 Up,
 Down,
 Left,
 Right,
 None
};

enum Actions {
 Jump,
 Action,
 Run,
 NoAction
};

Directions CurrentDirection;
Actions CurrentAction;


so am I missing something here? Do I need to import or update the values somehow. Because I don't get an error
Title: Re: Do I have to import enums?
Post by: Khris on Sun 13/02/2011 18:48:25
enums are mainly supposed to replace arbitrary numbers in the parameter list of a function.

If you put "Directions CurrentDirection;" in the header, you're creating one independent int variable for each script.

Put this in the header:
import Directions CurrentDirection;

and this in the main script:

Directions CurrentDirection;
export CurrentDirection;


Note that you can just use "int" instead of "Directions", the point of an enum would be that if you have a function like this:
void SetDirection(Directions dir) {
  CurrentDirection = dir;
}


And you type "SetDirection(", the auto-complete window pops up showing Up, Down, etc.
Title: Re: Do I have to import enums?
Post by: mode7 on Sun 13/02/2011 19:40:04
Thanks Khris! That fixed it!