|
Goombert
|
|
Reply #1 Posted on: May 19, 2016, 03:58:15 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
You are missing a semicolon and ENIGMA only allows structs in Definitions, please see the Wiki page. http://enigma-dev.org/docs/Wiki/StructuresIt is important to realize that structures and classes cannot be defined in EDL as with other code. They must be defined in Definitions, as with other C++ functions. Then they can be instantiated and used in your EDL code. In other words, the above example code could not be placed in, say, an object's Create event. It must go in Definitions.
You can find Definitions under Build->Settings->ENIGMA->General->Definitions Button Though I did also try this myself and could not get it to work, it seems that the dot operator is broken. itemStats stats; stats.amount = 66; if (stats.amount == 66) { show_message(string("hello")); }
struct itemStats { string itemID = ""; int amount = 1; };
error: invalid cast from type 'itemStats' to type 'int' if((enigma::varaccess_amount(int(stats))== 66)) ^
|
|
« Last Edit: May 19, 2016, 07:02:26 am by Robert B Colton »
|
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.
|
|
|
rotenKleber
|
|
Reply #2 Posted on: May 19, 2016, 10:35:01 am |
|
|
Joined: May 2016
Posts: 9
|
Aha, thank you very much. Those definitions are quite handy. I was a bit confused with the final semicolon, as the example over at http://enigma-dev.org/docs/Wiki/ENIGMA:Specification says 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() { destroy_radius(x,y,radius); } }
Without the final semicolon
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #3 Posted on: May 19, 2016, 10:55:48 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
I just tested myself again, and it does want the semicolon in Definitions. I think we planned/plan to make the semicolon optional but never got around to it. Basically, our GML->C++ compiler is not run over Definitions right yet, so Definitions is just pure C++.
This I got to actually compile:
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() { } };
circle *test = new circle();
test.x = 539;
show_message(string(test.x));
I'm surprised that new is required otherwise the dot operator does not work. That would be a question to ask Josh, but at least for now using structs like that works.
|
|
« Last Edit: May 19, 2016, 10:57:36 am by Robert B Colton »
|
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.
|
|
|
|
Goombert
|
|
Reply #5 Posted on: May 19, 2016, 11:40:05 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
No, you need the star, it's a C++ pointer.
itemStats *stats = new itemStats(); You probably do need to delete them as well, but that would maybe be better answered by Josh. I would go ahead and delete them anyway.
|
|
|
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.
|
|
|
|
Goombert
|
|
Reply #7 Posted on: May 19, 2016, 12:17:37 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
That's weird, I used it in the create event, give me a minute and I'll test.
Edit: Just tested my code from above in a script and called it from create, worked fine. So let me test the struct you are using.
Edit 2: Nope, I just tested again, it worked fine for me.
Definitions
struct itemStats { string itemID = ""; int amount = 1; };
scr_0
itemStats *test = new itemStats();
test.amount = 539;
show_message(string(test.amount));
Create event:
scr_0();
|
|
« Last Edit: May 19, 2016, 12:24:26 pm by Robert B Colton »
|
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.
|
|
|
|
Goombert
|
|
Reply #9 Posted on: May 19, 2016, 12:49:55 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Ahhhh, I bet I know why, are you on Linux? (I see your penguin). If so, then you are probably using GCC which is a little different than the MinGW I am using on Windows.
You could try making the cast explicit:
test.amount = (int)539; Or just change amount from int to var in the struct.
|
|
|
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.
|
|
|
|
Goombert
|
|
Reply #11 Posted on: May 19, 2016, 01:06:41 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Try using -> instead of the . operator. Definitely do not try using a different compiler, we want GCC to work, GCC is the defacto. For now anyway.
|
|
|
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.
|
|
|
|
Goombert
|
|
Reply #13 Posted on: May 19, 2016, 01:43:02 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Shoot, I'm about out of ideas until Josh gets here to ask. He should be here later tonight.
What is the output of gcc -v in a terminal?
|
|
« Last Edit: May 19, 2016, 01:47:20 pm by Robert B Colton »
|
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.
|
|
|
Goombert
|
|
Reply #14 Posted on: May 19, 2016, 01:50:31 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Oh I think I know what the problem is thanks to Rusky. I do not think we turned on C++11 for Linux yet. Try using this rewritten struct, c++98 does not support default values like that.
struct itemStats { string itemID; int amount;
itemStats() : itemID(""), amount(1) { } };
|
|
|
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.
|
|
|
|