Pages: 1 2 »
  Print  
Author Topic: Using EDL in LateralGM  (Read 2773 times)
Offline (Unknown gender) rotenKleber
Posted on: May 19, 2016, 12:13:23 AM

Member
Joined: May 2016
Posts: 9

View Profile Email
Okie Doke, I'm not really used to Enigma-Dev/LateralGM, so please don't beat me up if I should have known this.

I was happily making game, when I needed a well placed struct. Attempting to build the struct in a script that ran at the start of the game, I found that Enigma did not find my struct to mean anything

scr_init:
Code: [Select]
struct itemStats {
string itemID = "";
int amount = 1;
}

made

error:
Code: [Select]
Syntax error in script `scr_init'
Line 1, position 18 (absolute 17): Unterminated brace at this point

So is there some way I failed in implementing my EDL? Was a script a bad place to put it? Is my struct malformed?
Logged
Offline (Male) Goombert
Reply #1 Posted on: May 19, 2016, 03:58:15 AM

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

View Profile
You are missing a semicolon and ENIGMA only allows structs in Definitions, please see the Wiki page.

http://enigma-dev.org/docs/Wiki/Structures

Quote from: ENIGMA Wiki
It 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.
Code: (EDL) [Select]
itemStats stats;
stats.amount = 66;
if (stats.amount == 66) {
        show_message(string("hello"));
}
Code: (EDL) [Select]
struct itemStats {
        string itemID = "";
        int amount = 1;
};
Quote from: Compile Output
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.

Offline (Unknown gender) rotenKleber
Reply #2 Posted on: May 19, 2016, 10:35:01 AM

Member
Joined: May 2016
Posts: 9

View Profile Email
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
Quote
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
Offline (Male) Goombert
Reply #3 Posted on: May 19, 2016, 10:55:48 AM

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

View Profile
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:
Code: (C) [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() { }
};

Code: (EDL) [Select]
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.

Offline (Unknown gender) rotenKleber
Reply #4 Posted on: May 19, 2016, 11:17:20 AM

Member
Joined: May 2016
Posts: 9

View Profile Email
Haha so I need to dynamically allocate all my structs? Do I also need to free them, then?
And the dot operator replaces the "->" operator?

Edit-
Okie Dokie I tried this in EDL

Code: [Select]
itemStats stats = new itemStats();

But alas

Code: [Select]
Line 8, position 34 (absolute 297): Unknown function or script `itemStats'
« Last Edit: May 19, 2016, 11:21:05 AM by rotenKleber » Logged
Offline (Male) Goombert
Reply #5 Posted on: May 19, 2016, 11:40:05 AM

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

View Profile
No, you need the star, it's a C++ pointer.

Code: (EDL) [Select]
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.

Offline (Unknown gender) rotenKleber
Reply #6 Posted on: May 19, 2016, 11:55:24 AM

Member
Joined: May 2016
Posts: 9

View Profile Email
Oh my bad, I did have that asterisk in there.
Code: [Select]
itemStats *stats = new itemStats();

Perhaps this code cannot be implemented in scripts (EDL)? Can I only use that with C++ in definitions?
Logged
Offline (Male) Goombert
Reply #7 Posted on: May 19, 2016, 12:17:37 PM

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

View Profile
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
Code: (EDL) [Select]
struct itemStats {
        string itemID = "";
        int amount = 1;
};

scr_0
Code: (EDL) [Select]
itemStats *test = new itemStats();

test.amount = 539;

show_message(string(test.amount));

Create event:
Code: (EDL) [Select]
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.

Offline (Unknown gender) rotenKleber
Reply #8 Posted on: May 19, 2016, 12:46:51 PM

Member
Joined: May 2016
Posts: 9

View Profile Email
Strange, I tried your exact examples, and got this error:

Code: [Select]
.h:40:36: error: cast from ‘itemStats*’ to ‘int’ loses precision [-fpermissive]
   enigma::varaccess_amount(int(test))= 539;
                                    ^
/home/kleber/.enigma/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:41:58: error: cast from ‘itemStats*’ to ‘int’ loses precision [-fpermissive]
   show_message(toString(enigma::varaccess_amount(int(test))));
Logged
Offline (Male) Goombert
Reply #9 Posted on: May 19, 2016, 12:49:55 PM

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

View Profile
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:
Code: (EDL) [Select]
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.

Offline (Unknown gender) rotenKleber
Reply #10 Posted on: May 19, 2016, 01:01:40 PM

Member
Joined: May 2016
Posts: 9

View Profile Email
Ah, yes, I am on GNU/Linux

Hm, neither of those fixed it. Would it work if I used a different compiler?
Logged
Offline (Male) Goombert
Reply #11 Posted on: May 19, 2016, 01:06:41 PM

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

View Profile
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.

Offline (Unknown gender) rotenKleber
Reply #12 Posted on: May 19, 2016, 01:08:03 PM

Member
Joined: May 2016
Posts: 9

View Profile Email
That results in the
Code: [Select]
Syntax error in script `scr_0'
Line 3, position 6 (absolute 43): Expected primary expression before operator
Logged
Offline (Male) Goombert
Reply #13 Posted on: May 19, 2016, 01:43:02 PM

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

View Profile
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.

Offline (Male) Goombert
Reply #14 Posted on: May 19, 2016, 01:50:31 PM

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

View Profile
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.

Code: (EDL) [Select]
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.

Pages: 1 2 »
  Print