I’d like to use an enum (I think!) to represent a game state which is available to various classes (files) like this:
enum State {
HIDING;
SEEKING;
}
Am I right in thinking this has to be declared outside of any class and is therefore only accessible in the file in which it is declared? I can’t seem to make it work any other way.
Thanks for the reply. But doesn’t that set up mean that the value of the static variable ‘state’ can only changed within that class? I I have a class Test2 in another file it wouldn’t know about the enum so how could code in that class change the state?
class Test {
public static var state = State.HIDING;
static function main() {
trace(Test.state);
Test2.seek();
trace(Test.state);
Test2.hide();
trace(Test.state);
}
}
enum State {
HIDING;
SEEKING;
}
Test2.hx:
class Test2 {
public static function hide() {
Test.state = State.HIDING;
}
public static function seek() {
Test.state = State.SEEKING;
}
}
Test2.hx:7: characters 21-26 : Type not found : State
Test2.hx:3: characters 21-26 : Type not found : State
Admittedly I wouldn’t be calling functions in Test2 from Test to set the state but I might want to change the state within some other function in Test2, eg if Test2 handled the game menu I might want to change the game state from one of its methods.