Do I have to import enums? (SOLVED)

Started by mode7, Sun 13/02/2011 18:11:47

Previous topic - Next topic

mode7

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:

Code: ags

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

Khris

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:
Code: ags
import Directions CurrentDirection;


and this in the main script:

Code: ags
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:
Code: ags
void SetDirection(Directions dir) {
  CurrentDirection = dir;
}


And you type "SetDirection(", the auto-complete window pops up showing Up, Down, etc.

mode7


SMF spam blocked by CleanTalk