• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

OFFICIAL GMS 2.3.0 BETA ANNOUNCEMENT

Status
Not open for further replies.
If it's really out of beta ticket , YYC should close my ticket instead of leaving it open for 11 days
Why make people wait while it's over
Sorry for my bad English
 

kburkhart84

Firehammer Games
Have you checked the yy json files ? Maybe it's something that you can fix by yourself (in case of missing resources add their names again - as they are in folders), and also report a bug what was wrong/missing from file.
I'm pretty sure there was already a bug reported(seemingly several people know about it too). I checked the files and didn't find anything in particular. As you mentioned though maybe the next update will have the problem fixed. I haven't completely given up on using it, just making sure to be extra prudent with backing up, etc...
 
There's a way to do it that makes questions 1-4 all irrelevant.
Right, the idea I was messing with was how to do an immediate mode imgui style setup where the buttons only exist in the draw event where you can hide & expand them on the fly but now I'm thinking maybe that's not a situation where the new features really apply and it's simpler to just do it the normal way since the biggest hassle with menus was having to create and manage them with tons of arrays and enums or grids and lists etc which is why I was looking into imguis in the first place.

But after reading your post I roughed out another idea that plays along with GMS's Events but uses the new features just to clean & simplify things a ton compared to how I would have done this before with obj_menus and obj_buttons etc:
GML:
function Menu(_x1, _y1) constructor {
    x1        = _x1;
    y1        = _y1;
    btn_count = 0;

    add_button = function(_label, _script) {
        Buttons[btn_count] = new Button(x1, y1 + (20 * btn_count), _label, _script);
        btn_count = array_length(Buttons);
    }

    do_buttons = function(_function) {
        var _i = 0;
        repeat(btn_count) {
            Buttons[_i++]._function;
        }
    }
}

function Button(_x1, _y1, _label, _script) constructor {
    width  = 100;
    height =  20;
    x1     = _x1;
    y1     = _y1;
    label  = _label;
    script = _script;

    update = function() {
        bg_color = c_white;

        //hovering
        if (point_in_rectangle(mouse_x, mouse_y, x1, y1, x1 + width, y1 + height)) {
            bg_color = hovering_color;

            //clicked
            if (mouse_check_button_pressed(mb_left)) {
                bg_color = clicked_color;
                script_execute(id, script);
            }
        }
    }

    draw = function() {
        draw_set_color(bg_color);
        draw_rectangle(x1, y1, x1 + width, y1 + height, false);

        draw_set_color(c_black);
        draw_text(x1, y1, label);
    }
}

//--------------------------------------------------
//obj_menu
//--------------------------------------------------
//Create Event
menu = new Menu(200, 200);
menu.add_button("New",  scr_button_new );
menu.add_button("Open", scr_button_open);
menu.add_button("Save", scr_button_save);
menu.add_button("Quit", scr_button_quit);

//Step Event
menu.do_buttons(update);

//Draw Event
menu.do_buttons(draw);
I can't get over how lightweight the code looks using Structs and not having enums and long function names to prevent conflicts etc lol Even within the new features you can keep reducing code so it's nice and clean instead of having monotonous big ugly blocks of code like:
GML:
var _y = 0;
menu = new Menu(200, 200, [
    new Button(0, menu.x, menu.y + (20 * _y++), "New",  scr_button_new ),
    new Button(0, menu.x, menu.y + (20 * _y++), "Open", scr_button_open),
    new Button(0, menu.x, menu.y + (20 * _y++), "Save", scr_button_save),
    new Button(0, menu.x, menu.y + (20 * _y++), "Quit", scr_button_quit)
]);
...or making a "new_button" script up in the Scripts folder except what if the button is for a different type of menu like an icon toolbar so instead it has to be "new_menu_button" and "new_toolbar_button" etc etc
Don't just think of the OOP additions as extra prefixes on scripts. Instead think of it as a way to make lightweight, independent entities with associated actions.
Ya this is why I'm posting right now when I don't even have the beta yet lol this thread has the most eyes on it of people who actually know how to use these features so I figure it's a great opportunity to get some insights from you guys on what sort of ways you hope newbies approach using these features. Because this whole thing is a bit of a paradigm shift in thinking of how to approach common coding situations I'm in and it's tempting to get caught up in trying to apply the new stuff to literally every situation when sometimes the best way is just sprinkling a bit of it in here and there and not trying to smash every screw into the 2x4 just because you got a new hammer lol

Thanks for the help! I'm going through the code of my game and looking at "how would I redo & simplify this using the new features" so that when the time comes I'll be able to hit the ground running on rewriting everything.

Actually one new question I have after figuring out the above code is can you do an "other.var = value;" where "other" would be whatever object is calling the "new Struct" or a Struct.function() inside the Struct? Like how you can do a "with (obj_whatever) {other.var = value;}" So that all my buttons would know their parent is the menu and the menu would know its parent is the obj_gui that created it, without having to manually keep track of that by setting a parent_id?
 

Amon

Member
Right, the idea I was messing with was how to do an immediate mode imgui style setup where the buttons only exist in the draw event where you can hide & expand them on the fly but now I'm thinking maybe that's not a situation where the new features really apply and it's simpler to just do it the normal way since the biggest hassle with menus was having to create and manage them with tons of arrays and enums or grids and lists etc which is why I was looking into imguis in the first place.

But after reading your post I roughed out another idea that plays along with GMS's Events but uses the new features just to clean & simplify things a ton compared to how I would have done this before with obj_menus and obj_buttons etc:
GML:
function Menu(_x1, _y1) constructor {
    x1        = _x1;
    y1        = _y1;
    btn_count = 0;

    add_button(_label, _script) {
        Buttons[btn_count] = new Button(x1, y1 + (20 * btn_count), _label, _script);
        btn_count = array_length(Buttons);
    }

    do_buttons(_function) {
        var _i = 0;
        repeat(btn_count) {
            Buttons[_i++]._function;
        }
    }
}

function Button(_x1, _y1, _label, _script) constructor {
    width  = 100;
    height =  20;
    x1     = _x1;
    y1     = _y1;
    label  = _label;
    script = _script;

    update = function() {
        bg_color = c_white;

        //hovering
        if (point_in_rectangle(mouse_x, mouse_y, x1, y1, x1 + width, y1 + height)) {
            bg_color = hovering_color;

            //clicked
            if (mouse_check_button_pressed(mb_left)) {
                bg_color = clicked_color;
                script_execute(id, script);
            }
        }
    }

    draw = function() {
        draw_set_color(bg_color);
        draw_rectangle(x1, y1, x1 + width, y1 + height, false);

        draw_set_color(c_black);
        draw_text(_x1, _y1, _label);
    }
}

//--------------------------------------------------
//obj_menu
//--------------------------------------------------
//Create Event
menu = new Menu(200, 200);
menu.add_button("New",  scr_button_new );
menu.add_button("Open", scr_button_open);
menu.add_button("Save", scr_button_save);
menu.add_button("Quit", scr_button_quit);

//Step Event
menu.do_buttons(update);

//Draw Event
menu.do_buttons(draw);
I can't get over how lightweight the code looks using Structs and not having enums and long function names to prevent conflicts etc lol Even within the new features you can keep reducing code so it's nice and clean instead of having monotonous big ugly blocks of code like:
GML:
var _y = 0;
menu = new Menu(200, 200, [
    new Button(0, menu.x, menu.y + (20 * _y++), "New",  scr_button_new ),
    new Button(0, menu.x, menu.y + (20 * _y++), "Open", scr_button_open),
    new Button(0, menu.x, menu.y + (20 * _y++), "Save", scr_button_save),
    new Button(0, menu.x, menu.y + (20 * _y++), "Quit", scr_button_quit)
]);
...or making a "new_button" script up in the Scripts folder except what if the button is for a different type of menu like an icon toolbar so instead it has to be "new_menu_button" and "new_toolbar_button" etc etc

Ya this is why I'm posting right now when I don't even have the beta yet lol this thread has the most eyes on it of people who actually know how to use these features so I figure it's a great opportunity to get some insights from you guys on what sort of ways you hope newbies approach using these features. Because this whole thing is a bit of a paradigm shift in thinking of how to approach common coding situations I'm in and it's tempting to get caught up in trying to apply the new stuff to literally every situation when sometimes the best way is just sprinkling a bit of it in here and there and not trying to smash every screw into the 2x4 just because you got a new hammer lol

Thanks for the help! I'm going through the code of my game and looking at "how would I redo & simplify this using the new features" so that when the time comes I'll be able to hit the ground running on rewriting everything.

Actually one new question I have after figuring out the above code is can you do an "other.var = value;" where "other" would be whatever object is calling the "new Struct" or a Struct.function() inside the Struct? Like how you can do a "with (obj_whatever) {other.var = value;}" So that all my buttons would know their parent is the menu and the menu would know its parent is the obj_gui that created it, without having to manually keep track of that by setting a parent_id?
I'm going through your code with a needle eye. I'm actually getting how this works now. Off to experiment.
 
I'm going through your code with a needle eye. I'm actually getting how this works now. Off to experiment.
lol I hope it helps! I'm picking general common situations to post that I think other people trying to understand this stuff would be able to relate to...I'm sure some of my syntax is off and there's probably even more optimal tricks for doing some of this but after doing these little roughing out exercises I feel like I have a much better grasp on how to apply these things to my code. I'm legit excited to get to actual work on my game and watch huge cumbersome masses of code get thrown out as I rewrite stuff into nice clean lightweight beautiful code that I'll actually understand when I come back to part of it 2 months later lol

Edit: actually I bet I could even put the button inside the menu........

Edit2: lol ok is this just getting silly? I can't even tell anymore:
GML:
function Menu(_x1, _y1) constructor {
    x1        = _x1;
    y1        = _y1;
    btn_count = 0;

    add_button = function(_label, _script) {
        Buttons[btn_count] = {
            width  = 100;
            height = 20 * other.btn_count;  //does an "other" command work here?
            x1     = other.x1;              //or is there some equivalent so these
            y1     = other.y1;              //vars are from just outside this Struct's {brackets}
            label  = _label;
            script = _script;

            update = function() {
                bg_color = c_white;

                //hovering
                if (point_in_rectangle(mouse_x, mouse_y, x1, y1, x1 + width, y1 + height)) {
                    bg_color = hovering_color;

                    //clicked
                    if (mouse_check_button_pressed(mb_left)) {
                        bg_color = clicked_color;
                        script_execute(id, script);
                    }
                }
            }

            draw = function() {
                draw_set_color(bg_color);
                draw_rectangle(x1, y1, x1 + width, y1 + height, false);

                draw_set_color(c_black);
                draw_text(x1, y1, label);
            }
        }

        btn_count = array_length(Buttons);
    }

    do_buttons = function(_function) {
        var _i = 0;
        repeat(btn_count) {
            Buttons[_i++]._function;
        }
    }
}

//--------------------------------------------------
//obj_menu
//--------------------------------------------------
//Create Event
menu = new Menu(200, 200);
menu.add_button("New",  scr_button_new );
menu.add_button("Open", scr_button_open);
menu.add_button("Save", scr_button_save);
menu.add_button("Quit", scr_button_quit);

//Step Event
menu.do_buttons(update);

//Draw Event
menu.do_buttons(draw);
It seems like you could theoretically put an entire game inside one huge game Struct, if you were crazy enough lol but I learned my lesson already with trying to make things as compact as possible while throwing away easy readability coming back to the code later, so even if something like this is technically possible, I think I would stick to my previous post where the Button is separate from the Menu which feels easier to grasp at a glance
 
Last edited:

kburkhart84

Firehammer Games
About the corrupt asset browser bug...I went ahead and reported it. I really thought someone had said they already did, but I couldn't find it(I wanted to just add a comment that I had the same issue). If someone else has had the same issue, they could add there project and/or notes to the topic.
 
D

Deleted member 45063

Guest
Pretty nice how you can arbitrarily extend structs.
GML:
///
/// This function will extend the supplied struct (ref) with the fields and methods in the computed
/// extension struct. The extension struct will be ext if this is a struct reference, otherwise it
/// will be the struct returned by executing ext without any arguments.
///
/// Values in the extension will be copied verbatim to the supplied struct, overriding any
/// potentially existing value. The only exceptions are methods that are bound to the extension
/// itself. These will be patched to be bound to ref instead, in order to retain their semantics.
///
/// The extended struct reference will be returned for convenience, however this reference will be
/// exactly the value of ref as the struct is modified in place.
///
function extend_with(ref, ext) {
  var extension = ext;
  if (is_method(ext))
    extension = ext();
  else if (is_real(ext) && script_exists(ext))
    extension = script_execute(ext);
  // There is no way to check if ext is a constructor so assume it is if nothing else worked,
  // note that this means the function code is effectively executed twice (reason why ID is 1 in
  // the output below).
  if (!is_struct(extension))
    extension = new ext();

  var names = variable_struct_get_names(extension);
  var count = array_length(names);

  for (var i = 0; i < count; i++) {
    var value = variable_struct_get(extension, names[i]);
    if (is_method(value) && method_get_self(value) == extension) {
      variable_struct_set(ref, names[i], method(ref, value));
    } else {
      variable_struct_set(ref, names[i], value);
    }
  }

  return ref;
}
GML:
function Example() constructor {
  value = "Hello World";
}

function IdExt() constructor {
  static __next_id = 0;
  struct_id = __next_id++;
}

ToArrayExt = {
  to_array: function () {
    var names = variable_struct_get_names(self);
    var count = array_length(names);
 
    var next  = 0;
    var array = array_create(count);
 
    for (var i = 0; i < count; i++) {
      var name = names[i];
      if (string_char_at(name, 1) == "_")
        continue;
     
      var value = variable_struct_get(self, name);
      if (is_method(value))
        continue;
     
      array[next++] = value;
    }
 
    if (next != count)
      array_resize(array, next);
    return array;
  }
};

show_debug_message("===== extend_with =====");

var example = new Example();
show_debug_message(example);

extend_with(example, IdExt);
show_debug_message(example);

extend_with(example, ToArrayExt);
show_debug_message(example.to_array());

extend_with(example, function () {
  return {
    toString: function () {
      return "example";
    }
  };
});
show_debug_message(example);

show_debug_message("=======================");
GML:
===== extend_with =====
{ value : "Hello World" }
{ struct_id : 1, value : "Hello World" }
[ 1,"Hello World" ]
example
=======================

This should allow for some really nice enhancing of existing modules / structs easily.
 

XanthorXIII

Member
If you do get in the Beta, the first thing I recommend doing is going into preferences and changing the location of your projects to a folder that you create instead of your GameMaker Project folder. That way you can copy your projects to that folder and not have this cause any loss of data.
 
Last edited:

FoxyOfJungle

Kazan Games
I know that this is not the best place to suggest something, but is there any possibility of an Audio frequency analyzer using the FFT Algorithm? (I mean, it doesn't need to be added in this version, it's an idea)

Maybe, or not, it is possible to do this with buffers, but I find this very complex, I believe that integrated functions would be more pleasant.

With that it would be possible to get the beat of the songs and there would be more possibilities to create different and interactive games using this, I think it would be incredible!
Of course, it's just my humble suggestion / opinion.
 
Last edited:

Zhanghua

Member
I know that this is not the best place to suggest something, but is there any possibility of an Audio frequency analyzer using the FFT Algorithm? (I mean, it doesn't need to be added in this version, it's an idea)

Maybe, or not, it is possible to do this with buffers, but I find this very complex, I believe that integrated functions would be more pleasant.

With that it would be possible to get the beat of the songs and there would be more possibilities to create different and interactive games using this, I think it would be incredible!
Of course, it's just my humble suggestion / opinion.
Use Extension, FFT is pure algorithm, so it's easy on some way.
 

FoxyOfJungle

Kazan Games
Use Extension, FFT is pure algorithm, so it's easy on some way.
But it's not always multiplatform, I've used one of MSTOP's for Windows, but it's not very good, sometimes it crashes.

I would have to do an extension for each platform, and doing extension for Android is something I never did, I don't know anything about Java. And for most the people would be difficult to implement the algorithm
 
Last edited:

Gunner

Member
Please read the full line I no where said this is small or little feature ...I mentioned about all little changes we got so far for which we had to wait for ages …..and for current changes I clearly mentioned " now finally when something is happening" .
as for supporting the company many here have always supported yoyogames even when we get gms1.4 repackaged with eye candy ui . and even less features then previous editor, we did supported it .the features you are adding in 2.3 should have been in gms2 in first place.
in gms we had to click 5 times for something now we have to click around 8-10 times , we are still changing our habbits instead of complaining to yoyogames .
No comment on Ads , monetization ???
see if you want to defend and don't want to accept its your call , you are defending company but don't be surprised when people will start looking for alternatives ..and that too free ones which are more intuitive and full of features.
there must be a reason why after so many years and so many loyal consumer base yoyogames still is a small company . people here try to be diplomatically correct but facts cant change.

as for people saying i am whining because i have no access well … I have always supported the company , despite of publishing most of my work with unity
GameMaker for Windows
GameMaker:HTML5
GameMaker: Studio Professional
HTML5 Export
Android Export
iOS Export
Mac Export
Ubuntu Export
Windows UWP

and I have gms2 with mobile html5 web etc on two of my accounts .but these new members who barely created account few days back wont understand it now .
That's literally a $15 humble bundle package back then and you're acting like you bought the ENTIRE master collection at full price, LOL.

and wow, you're so entitled. You should probably quit whining and just keep using Unity that you love so much. I bet if YYG releases the beta publicly without restriction you're gonna complain all day about them reLeAsInG a bUggY MeSs tO pAyIng CuStOmErS, hurr durr.
 

drandula

Member
About the corrupt asset browser bug...I went ahead and reported it. I really thought someone had said they already did, but I couldn't find it(I wanted to just add a comment that I had the same issue). If someone else has had the same issue, they could add there project and/or notes to the topic.
I just imported project from 2.2 to 2.3 beta and experienced first time Asset Browser bug, where I couldn't see any assets of project. I closed Asset Browser and did 'Reset Layout' (option in top bar), after procedure Asset Browser showed assets correctly.
 
Last edited:
M

Misu

Guest
I receiveed my beta access today woooo!

Now I need to explore and learn what are the new features in the GML environment. I like to know what can finally do with this.
 

Amon

Member
I receiveed my beta access today woooo!

Now I need to explore and learn what are the new features in the GML environment. I like to know what can finally do with this.
Welcome aboard. There are 3 rules. Rule 1: You don't talk about rule 2. Rule2: You don't mention rule 3. Rule 3: something that can make this rubbish post more exciting. :/
 

kburkhart84

Firehammer Games
I just imported project from 2.2 to 2.3 beta and experienced first time Asset Browser bug, where I couldn't see any assets of project. I closed Asset Browser and did 'Reset Layout' (option in top bar), after procedure Asset Browser showed assets correctly.
You must be Tero! That said, the idea didn't actually work in my case. The assets didn't disappear right when I imported the project though, rather later on after having done some work with it. I think I'm getting the bug they mentioned in my topic about it "going crazy" when you don't use the default folder structure and combine multiple assets into the same folders.
 

TheMagician

Member
Quick question about this example in the manual:

GML:
Vector2 = function(_x, _y) constructor
    {
    x = _x;
    y = _y;
    static Add = function( _other )
        {
        x += _other.x;
        y += _other.y;
        }
    }
Why exactly are we using the keyword static for that function? Am I right in thinking that it is because we save memory?
 

kburkhart84

Firehammer Games
The static keyword as I understand it is to make it only initiate/initialize the variable once, and use that same copy in all instances of the struct. Normally, that function gets copied each time you create an instance of that struct. But putting static ahead of it makes it only have one copy of that function in memory.
 

TheMagician

Member
Thank you, guys!

And while we are at it, another question: what is the scope of the variables x and y in this Vector2-example? Since there is no var keyword I would assume they are scoped to the instance that creates the struct (using the new keyword)?

However, wouldn't that mean that if I create multiple of these structs in the same instance that the values for x and y would always be overwritten by the new struct?
 

kburkhart84

Firehammer Games
Those variables are kind of like instance variables, scoped to the struct itself. Each struct will have its own copy of those variables. To later access them, you will need to do either a with(){} statement, or use '.' syntax, just like with instances. This is why they are basically considered "light-weight" objects, because they generally work the same way, just with no built-in variables or events like with objects.

EDIT: To clarify, they don't belong to the instance that the struct belongs to, rather to the struct itself. If you copy a reference of that struct to another instance, those variables stay belonging to the struct, not some other instance.
 
S

Sybok

Guest
Guys don't forget the ticket numbers please.. I think there is no hope for me :( (170319)
I‘m in the 169900’s somewhere.

I’m in no rush. It’s not a matter of life of death for me, like it is for others here.

How did humanity ever survive on 2.2? :p
 

Karlstens

Member
I‘m in the 169900’s somewhere.

I’m in no rush. It’s not a matter of life of death for me, like it is for others here.

How did humanity ever survive on 2.2? :p
Maybe we won't >_> We're in the midst of a global pandemic after all...
 
Those variables are kind of like instance variables, scoped to the struct itself. Each struct will have its own copy of those variables. To later access them, you will need to do either a with(){} statement, or use '.' syntax, just like with instances. This is why they are basically considered "light-weight" objects, because they generally work the same way, just with no built-in variables or events like with objects.

EDIT: To clarify, they don't belong to the instance that the struct belongs to, rather to the struct itself. If you copy a reference of that struct to another instance, those variables stay belonging to the struct, not some other instance.
Do you know off-hand if it's possible to get variables from outside the struct, like manipulating the image_alpha of whatever instance created the struct? The equivalent of "other." essentially. Or do you have to pass in whatever vars you need and return new versions of them?
 
H

Homunculus

Guest
@BPOutlaws_Jeff I haven't tested the use of other inside structs, but as far as I could see they are not tied to the generating instance in any way. Ideally you should pass the instance id to the constructor and / or set a variable inside the struct holding the instance id.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Some 2.3 trick I wanted to share,
I was trying to make real static methods (no need to have an instance) and came up with this work around:

Part1.PNG

this will allow to have a separate "entity" called MyObjectUtils (I created a #macro for simplicity) containing the static methods to use with MyObject. As you can see I used JSDocs to make an alias that uses the dot accessor MyObjectUtils.StaticCreation()

Part2.png

And believe it or not, it works. nNow we have autocompletion for nested methods. this is good for libraries and stuff. BUT, cus there is always a butt :p

Part3.PNG

as soon as we type the MyOjbectUtils the IDE knows a macro and hides the context help.
Already asked YYG what could be done regarding this and hope they allow it :) So just wanted to share knowledge.


[QUESTION]
Imagine this approach being used in a Vector2 struct constructor... I'm using this to separate methods that edit the current instance or create a new one.
What would feel more natural... using the vectorInstance.Add(vector) edits the current instance and VectorUtils.Add(vector1, vector2) returns a new one? or the other way around?

[NOTE] This is NOT really static but is as close as we can get right now :)
 
Last edited:

xDGameStudios

GameMaker Staff
GameMaker Dev.
Do you know off-hand if it's possible to get variables from outside the struct, like manipulating the image_alpha of whatever instance created the struct? The equivalent of "other." essentially. Or do you have to pass in whatever vars you need and return new versions of them?
This would be the best approach don't try to rely on the keywords like other it might not be always what you expect it to be.

GML:
function Puppeteer(instance) constructor
{
    _instance = instance;
   
    ChangePosition(x, y)
    {
        _instance.x = x;
        _instance.y = y;
    }
}

var puppeteer = new Puppeteer(playerInstance);

puppeteer.ChangePosition(100, 100);
show_debug_message(playerInstance.x) // 100
show_debug_message(playerInstance.y) // 100


puppeteer.ChangePosition(23, 222);
show_debug_message(playerInstance.x) // 23
show_debug_message(playerInstance.y) // 222
 

TheMagician

Member
Now that code-folding is added automatically (which I think is a great addition), is there any way to customize the color of the vertical code-folding lines? I have looked through the color options in the Text Editor Preferences but couldn't find anything. I find it a bit too bright and distracting from the actual code and would like to change it into a darker shade of gray.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Now that code-folding is added automatically (which I think is a great addition), is there any way to customize the color of the vertical code-folding lines? I have looked through the color options in the Text Editor Preferences but couldn't find anything. I find it a bit too bright and distracting from the actual code and would like to change it into a darker shade of gray.
I agree with this and would also like the option. Please file a bug in the Helpdesk forum for the beta. ;)
 
H

Homunculus

Guest
@xDGameStudios by mixing macros, functions and structs you can definitely do a lot of interesting stuff. The method you describe can also be used to create simple modules that do not even need a "struct instance". The GML changes in 2.3 open up so many possibilities, too bad the autocompletion is not as good right now.
 
as far as I could see they are not tied to the generating instance in any way. Ideally you should pass the instance id to the constructor and / or set a variable inside the struct holding the instance id.
var puppeteer = new Puppeteer(playerInstance);
Ok thanks, that's what I was assuming it was like. I'm picturing something where you might have nested structs where a function 3 structs deep needs to change variables in the struct 2 levels above it, and then use that result to affect a variable in whatever object called that 3 struct deep function. Doing that much nesting probably isn't good coding anyway lol I usually keep a parent_id or pass an id to whatever anyway but was just curious if structs came with some kind of automatic stuff for that.

I'm really liking how clean structs are, and getting more of a grasp on what situations to use them and when to use a script instead (it seems like I'll use them much more rarely now) and when to just use the traditional objects with all their Events and built-in attributes.
 
H

Homunculus

Guest
Ok thanks, that's what I was assuming it was like. I'm picturing something where you might have nested structs where a function 3 structs deep needs to change variables in the struct 2 levels above it, and then use that result to affect a variable in whatever object called that 3 struct deep function.
Well you could bind a method to the parent without actually saving its reference as a variable, but it's a bit contrivied, and you still need to pass a reference...

GML:
function Car() constructor {
  
    dir = 0;
   
}

function Wheel(_car) constructor {
   
    steer_left = method(_car, function() {
        dir -= 4;
    });
   
    steer_right = method(_car, function() {
        dir += 4;
    });
  
}

car = new Car();
wheel = new Wheel(car);
wheel.steer_right(); //increases car dir variable by 4
 
Status
Not open for further replies.
Top