Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enums #30

Open
darkhog opened this issue Jan 9, 2025 · 1 comment
Open

Add enums #30

darkhog opened this issue Jan 9, 2025 · 1 comment

Comments

@darkhog
Copy link

darkhog commented Jan 9, 2025

They could be declared like

enum enemytype
    goomba
    koopa
    hammerbro

then an enum variable could be declared like that:

enemytype enemy_type

and would basically be equivalent of

ct U ENEMY_GOOMBA     = 0
ct U ENEMY_KOOPA      = 1
ct U ENEMY_HAMMER_BRO = 2
U enemy_type

Basically, it would make the code prettier and with less possibility of accidental bugs (you'd have to consciously add another enemy type to the enum instead of hamming up and putting it spawn_enemy(4) when you meant enemy 3. Because enums would be basically numbers under the hood, they would be usable in a switch statements, like this:

enum scene
    main_menu
    main_game
vars
    scene current_scene = main_menu
switch current_scene
    case main_menu
        process_mainmenu()
        break
    case main_game
        process_maingame()
        break
    default:
        break

This would be great for state machines and would avoid the headache of having to define countless constants (also would spare the developer wondering why stuff breaks or doesn't work when wrong value was provided by accident).

@pubby
Copy link
Owner

pubby commented Jan 10, 2025

It's a good idea. I've thought about adding enums before, but it might be some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants