Skip to content

Why MSG code needs to be a int? #141

Description

@Gilgamesh64

In my libgdx code, i'm using the message handling features that this library offers, the only thing i must say is: why ints?
In my project i have this class:

public enum MSG {
DIALOGUE_TRIGGERED,
DIALOGUE_DONE,
BLOCK_WALLS,
...;
public int code;

static {
int counter = 0;
for (MSG msg : MSG.values()) {
msg.code = counter++;
}
}
}

It's an enum that auto assigns a code.
Then, each time i have to work with messages i do:

public void send(MSG msg) {
stageMsg.dispatchMessage(msg.code);
}

or

@OverRide
public boolean handleMessage(Telegram msg) {
if(msg.message == MSG.SWAP_FIGHT_STATE.code) swapFightingState();

return true;
}

Is there a specific reason for why it must be a int with no "built in" way to use strings or enums?
If there isn't i would be more then happy to implement it myself if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions