Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMLive.gml

Livecoding for GameMaker: Studio / GameMaker Studio 2 · By YellowAfterlife

[Fixed] Enumerators being misrecognized as variables

A topic by Indiebuild created Dec 30, 2017 Views: 904 Replies: 6
Viewing posts 1 to 6
(3 edits)

The title says all, this is my macros.gml script:

enum ia_combat //Current state of the IA
{
    neutral,    //default behaviour
    suspicious, //when hears a suspicious sound, go investigate
    alert,        //hears an alarming sound, warns nearby teammates
    fighting    //engaged combat, with player, shooting warns teammates
}

When I atempt to use the macro on the Enemy's Begin step, this happens:

[live][16:56:46] Runtime error: obj_enemy_simple:Step_1[L34,c11] `100274` (obj_enemy_simple) does not have a variable `ia_combat`

Even tho it works perfectly when not using live_result() on Begin Step;

System information:
Windows 8.1 Pro 64-bits.
GMS2 IDE: v2.1.3.189

Please, feel free to contact me via Twitter if necessary, it's the easiest way to reach me: @ThiagoJaqueta

EDIT: Odly, this only happens at this specific situation, I'm trying to find out what is causing this, but when I do this at the draw event, it works perfectly.

    var combat_str="";
    switch(ia_combat_state)
    {
            case ia_combat.neutral: combat_str="Neutral"; break;
            case ia_combat.suspicious: combat_str="Suspicious"; break;
            case ia_combat.alert: combat_str="Alert"; break;
            case ia_combat.fighting: combat_str="Fighting"; break;
    }
    draw_set_halign(fa_center);
    draw_set_valign(fa_bottom);
    draw_set_font(fnt_consolas);
    draw_text(x1,y2-12,combat_str);
Developer

1. Are you doing anything slightly unusual in that Begin Step event, like having a local variable named "ia_combat" (strange question, but I can't think of anything else that'd throw it off)
2. If you copy just the macros-script and the object into a separate project (commenting out/replacing with an empty script call anything referencing game-specific things), does the issue persist there?

I'd message you on Twitter but you have direct messages closed to those that you don't follow.

Sorry I took so long to reply, I could sewear that I was following you on twitter :/, welp, now I am, you should be able to contact me there now.

1. Nothing like that, the closest thing I have is "ia_combat_state", but even when I renamed the enum, the problem persisted.
2. Yes! Here, I uploaded a project for you to test it
Again, not sure what it is, when compiling without gmlive, it works perfectly. I'll try to do some testing in my end, regarding firewalls, if I manage to solve the issue I'll let you know.

Also, using live_call on the create event seems to give some errors as well.

Thanks.

Developer

Upon a small investigation the issue revealed to be due the comment between enum name and stat of enum code,

enum ia_combat // <this comment>
{
...
}

on game start, the game asks the server to send it a summary of what enums/macros/globalvars/etc. there are in project, and server sends a list of snippets in return. The client then quickly looks through snippets to figure out what are the names to look for in code to determine whether something should be used or not. And, well, for enums I have made the generally valid assumption that with syntax being "enum Name { ... }", the name is what is between "enum" and the following curly bracket, minus spaces. As you can guess from here, the extension was thinking that the enum's name was "ia_combat //Current state of the IA", and thus it wasn't being recognized in "live" code.

Moving the comment to be before the "enum" or after the opening curly bracket fixes the issue; I'll fix this for the next extension update.

Awesome! I'll keep that in mind until the next update.
Thanks for the help.

I had this issue as well, although in my case it wasn't because of a comment after the enum name.  I had the enums defined in the creation code of my first room.  When I moved them to a separate .gml file, that resolved the error.

Developer (1 edit)

Room creation code / instance creation code in particular isn't currently being checked for enum definitions, as room files are much bigger (thus slower to timely parse on demand) than object/script files while it is relatively uncommon to have global declarations in them.