Pages: 1
  Print  
Author Topic: Error implementing struct  (Read 26314 times)
Offline (Unknown gender) ojars
Posted on: May 31, 2019, 06:50:41 am
Member
Joined: May 2019
Posts: 16

View Profile
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, where this example worked on Goombert's computer. In Definitions I created a struct
Code: [Select]
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
Code: [Select]
///test_circle()

circle *test = new circle();
test.x = 200;
show_message(string(test.x));

In the o_game Create event
Code: [Select]
test_circle();
And in the Cleanup
Code: [Select]
delete 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?
Logged
Offline (Male) Goombert
Reply #1 Posted on: June 01, 2019, 03:44:47 am

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
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.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) ojars
Reply #2 Posted on: June 01, 2019, 04:55:20 am
Member
Joined: May 2019
Posts: 16

View Profile
Thanks, I'l be patient.
Logged
Offline (Unknown gender) ojars
Reply #3 Posted on: June 10, 2019, 02:04:51 pm
Member
Joined: May 2019
Posts: 16

View Profile
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
Code: [Select]
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
Quote
  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;

« Last Edit: June 10, 2019, 02:06:28 pm by ojars » Logged
Offline (Unknown gender) Dragonite
Reply #4 Posted on: June 13, 2019, 11:00:39 pm
Member
Joined: Mar 2017
Posts: 20

View Profile
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
Logged
Offline (Male) Goombert
Reply #5 Posted on: June 15, 2019, 01:04:05 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
Yeah, I recently had the chance to try GMEdit, it's pretty cool, I recommend too.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print