ENIGMA Forums
Outsourcing saves money => Issues Help Desk => Topic started by: ojars on May 31, 2019, 06:50:41 am
-
Hi!
I got an error, when tried to implement a struct into my code. I followed an example from https://enigma-dev.org/forums/index.php?topic=2674.msg25861#msg25861 (https://enigma-dev.org/forums/index.php?topic=2674.msg25861#msg25861), where this example worked on Goombert's computer. In Definitions I created a struct struct circle {
var x = 0, y = 0;
double radius;
double get_area() { return pi * radius * radius; } // Simple method
circle(double r = 1) { radius = r; }; // Optimizing this falls on the language plugin
~circle() { }
};
Script///test_circle()
circle *test = new circle();
test.x = 200;
show_message(string(test.x));
In the o_game Create event test_circle();
And in the Cleanupdelete test;
This is an error:
Syntax error in script `test_circle'
Line 3, position 26 (absolute 45): Unknown function or script `circle'
Then I put the code from script directly into the create event and the error is the same:
Event[0, 0] Check `o_game::create...Syntax error in object `o_game', Create event:0:
Line 4, position 26 (absolute 64): Unknown function or script `circle'
What's wrong in my code?
-
If I recall correctly, I think it's possible the definitions frame may be bugged and isn't saving. In other words, it reverted immediately after you closed the game settings frame. I am planning to look into this area soon now that I have fixed included file editing, but am extremely busy. I will update if I get any of it done, thank you for your patience. As you are discovering, ENIGMA may be rough around the edges, but this situation is drastically improving with our introduction of continuous integration testing.
-
Thanks, I'l be patient.
-
Eventually I found a right way how to implement structs: declaration should be done in Definitions, initialization should be done in Initialization and no need to create instance on the heap, simply put
circle test;
and the code works. Unfortunately, ENIGMA cannot recognize inline function get_area(). When I tried to calculate area with a function, I got an error Event[8, 0] Check `o_game::draw...Syntax error in object `o_game', Draw event:0:
Line 24, position 30 (absolute 768): Unknown function or script `get_area'
At least now I can use struct for lightweight objects, I believe it is more convenient than data structures;
-
Alternatively, you could try using GMEdit's type magic:
https://github.com/GameMakerDiscord/GMEdit/wiki/Using-type-magic
https://github.com/GameMakerDiscord/GMEdit/wiki/Using-%23import-magic#import-compkgsome-as-nsalias
-
Yeah, I recently had the chance to try GMEdit, it's pretty cool, I recommend too.