OFFICIAL GMS 2.3.0 BETA ANNOUNCEMENT

GML:
function demo(n) constructor{
    static abc = [n];
    static push1 = function(){
        abc[@ 0]++;
    }

    static push2 = function(){
        abc[0] += 2;
    }

    static show = function(){
        show_debug_message(abc);
    }
}


function test(){
    var a = new demo(2);//public.abc = [2], a.abc is the public one.
    var b = new demo(5);//public.abc = [2], b.abc is the public one and will not be initialed again

    a.push1();//public abc[0] = 2+1, a.abc is the public one.
    a.show();// show pulic abc = [3]
    a.push2();//private a.abc[0] = public abc[0] + 2; a has his private abc now, the abc below is not the pulic one and be initialed from the public.
    a.show();// show private a.abc = [5]
    a.push1();//private a.abc[0]++
    a.show();// show private a.abc = [6]
    a.push2();//private a.abc[0]+=2
    a.show();// show private a.abc = [8]

    b.push1();//public abc[0] = 3+1, , b.abc is the public one.
    b.show();// show pulic abc = [4]
    b.push2();//private b.abc[0] = public.abc[0] + 2; b has his private abc now, the abc below is not the pulic one and be initialed from the public.
    b.show();// show private b.abc = [6]
    b.push1();//private b.abc[0]++
    b.show();// show private b.abc = [7]
    b.push2();//private b.abc[0]+=2
    b.show();//show private b.abc = [9]
}
My Conclusion:
If struct only has public static member, it will operate the public one.
Once struct has it's own member, it will operate his private one and be initialed from the public.
so you can actually have "true static" variables
using:

GML:
function TimeCamera() constructor
{
    static staticVars = { times: ds_stack_create(), counter: 0 };
    
    static SnapShot = function()
    {
        ds_stack_push(staticVars.times, get_timer());
        staticVars.counter += 1; 
    }
    
    static Pop = function()
    {
        if (staticVars.counter == 0) return false;
        staticVars.counter -= 1; 
        return ds_stack_pop(staticVars.times);
    }
}
As structs are always passed as reference... you can change them at will ;)
and now all TimeCamera intances share the same static variables ;)

[NOTE] This is a useless example :p
 

Zhanghua

Member
GML:
function demo(n) constructor{
    static abc = {n:n};
    static push1 = function(){
        abc.n++;
    }

    static push2 = function(){
        abc = {n:abc.n+2};
    }


    static show = function(){
        show_debug_message(abc);
    }
}
GML:
function demo(n) constructor{
    static abc = [n];
    static push1 = function(){
        abc[@ 0]++;
    }

    static push2 = function(){
        abc[0] += 2;
    }

    static show = function(){
        show_debug_message(abc);
    }
}
@xDGameStudios
Thank you to tell me that the struct uses reference.
Yes, if we want to keep the static to be unique, just use it by avoiding the unreference operation, while not create another clone in member function.
Just use it, Not create another!
 
Last edited:
Interesting, so could I do this?:
GML:
function Enemy(_sprite_index) constructor {
    init(_sprite_index);//<-- this right here lol, will this make this idle->walk->idle loop start itself?

    init = function(_sprite_index) {//this wouldn't conflict with the above _sprite_index
        image_index = _sprite_index;//because this one will be inside the init scope right?
        idle(60);
    }

    idle = function(_duration) {
        if (!_duration--) {
            walk(choose(dir.left, dir.right), 60);
        }
    }

    walk = function(_direction, _duration) {
        switch (_direction) {
            //code to walk in the chosen _direction
        }

        if (!_duration--) {
            idle(irandom(6) * 10);
        }
    }
}

//Create Event
enemy = new Enemy(spr_goomba);//would the init event start by itself based on the above code?
...so that a constructor is self-starting instead of requiring an enemy.init(spr_goomba); line after the New? Because I can think of all sorts of ways to abuse that lol

One of the frustrating things I run into a lot is how you create an object which runs its Create Event, and you assign some stuff to it right after the instance_create line, but that stuff doesn't happen until the Step event so you've got this frame in limbo where if it's set to Visible it'll draw with the default Create settings so you have to have Visible false and then in the Step event run an init event that turns Visible on after stuff has been set up etc etc

That gets to be an even bigger mess when you're dealing with complex Spine related stuff and you need to get values from Animation Update but that's considered a Draw Event so it doesn't update until the object has been visible & drawn for a frame which means some values like bounding box points initialize up at 0,0 while the object is drawn elsewhere on the screen and then finally the Animation Update event gets called and the bbox points jump over to where the object is actually drawn so you have to disable collision for the first frame so the player doesn't get hit by the detached bounding box if they're in the top-left of the screen but then the first frame the enemy is visible it's invincible which looks unfair to the player if they see their bullet pass "through" the enemy because it was only on it for that first frame etc (SHMUP problems lol)

So I'm wondering if these new functions would allow for a creative streamlining of that whole hassle (I think the Variable Definitions feature are meant for this purpose but I use my own level editor so my objects are created on the fly in code instead of the GMS level editor where setting those Variables is an option)

Also can we do this?:
GML:
enemy = new Enemy(spr_goomba).walk(dir.left, 60);
...where we call a function in the same line we construct a New?
 

Zhanghua

Member
GML:
function Enemy(_sprite_index) constructor {
    _duration = 0;
    _state = 0;
    init = function(_sprite_index) {
        sprite_index = _sprite_index;
        idle(60);
    }

    idle = function(_duration) {
        _duration = _duration;
        _state = 0;
    }
   
    step = function(){//call enemy.step() in step event
        switch( _state ){
            case 0:
                if (!_duration--) {
                    show_debug_message("duration over")
                }
            break;
        }
    }
   
    init(_sprite_index);// you can call it inner function just in one event step.
}
BPOutlaws_Jeff
Something like this.
 
Any fancy animations made using sequences already ? I thought we gonna have a showcase here...
I was gonna have one "in a few days," but my "few days" is always few months. If only YYG had let me in sooner, there'd be a 50% chance of me having one done by now! :'D
The problem is that the animation I was working on had nothing to do with the current game I'm working on....once I realized that, it kinda took the wind out of my sails.

Something with this guy:


Just... a lot of work doing an animation for something I probably won't use for my current game. I thought "yay, sequences, this will be easy now!" But no, animation is a huge pain in the ass, no matter what tools you're using, obviously! :'D
Maybe I'll get back to it soon though, I dunno. Sequences are definitely cool as hell.
 

Crescent

Member
Still a bit more verbose than

GML:
function my_func( _value = 10 ) {
}
But yeah, that is probably more clear than using the argument stuff. ty
I prefer the Lua-esque syntax of

GML:
function foo(bar, ber, bir) {
    var foobar = bar || 0;
    var foober = ber || 5;
    var foobir = bir || 12;
}
... where the "OR" comparison denotes the value to substitute if the variable is undefined. Much less messy!
 

XanthorXIII

Member
Now that the Assets Browser has been re-designed to allow us to structure it anyway that we want, I'm trying to figure out how I want to go about this. I thought about doing something like
Code:
Player
    Sprites
    Functions
    Objects
    
Enemies
    Sprites
    Functions
    Objects


That's something I've been kicking around. Anyone else thought of how they may redo their stuff?
 

Amon

Member
I'm struggling with all this. Every time someone posts some code the layout is different. I'm still trying though. Any help for the below would be appreciated.

How would I set up something like this? A system that moves between rooms, has separate sections for the create/step/draw/drawgui events?

I am struggling to figure out how to glue everything together.
 

Zhanghua

Member
GML:
//All code is In Create Event
function my_func(_x,_y,_flag ) {
    if( _flag ){ show_debug_message([x,y]); }
    x = _x;
    y = _y;
}

id.my_func(0,0,true);//move to (0,0), and print its room position [1024,480]
temp = new id.my_func(400,400,false);// can't print cause [x,y] is undefined
id.my_func(110,110,true);//print [400,400] but the object's room position is [0,0]
temp = new id.my_func(600,600,false);// can't print cause [x,y] is undefined
id.my_func(110,110,true);//print [600,600] but the object's room position is [0,0]
id.my_func(330,330,true);//print [110,110] but the object's room position is [0,0]
@xDGameStudios

@FrostyCat



Is the code above executed normally?
 
Last edited:

Cameron

Member
Now that the Assets Browser has been re-designed to allow us to structure it anyway that we want, I'm trying to figure out how I want to go about this. I thought about doing something like
Code:
Player
    Sprites
    Functions
    Objects
   
Enemies
    Sprites
    Functions
    Objects


That's something I've been kicking around. Anyone else thought of how they may redo their stuff?
That would probably be a good way to organize it. I could see myself doing that once I finally get a hold of the beta.
 

drandula

Member
GML:
//All code is In Create Event
function my_func(_x,_y,_flag ) {
    if( _flag ){ show_debug_message([x,y]); }
    x = _x;
    y = _y;
}

id.my_func(0,0,true);//move to (0,0), and print its room position [1024,480]
temp = new id.my_func(400,400,false);// can't print cause [x,y] is undefined
id.my_func(110,110,true);//print [400,400] but the object's room position is [0,0]
temp = new id.my_func(600,600,false);// can't print cause [x,y] is undefined
id.my_func(110,110,true);//print [600,600] but the object's room position is [0,0]
id.my_func(330,330,true);//print [110,110] but the object's room position is [0,0]
@xDGameStudios

@FrostyCat



Is the code above executed normally?
I think there should be "constructor" keyword for function if you are going to use "new", otherwise be struct won't be created.
 

Zhanghua

Member
I think there should be "constructor" keyword for function if you are going to use "new", otherwise be struct won't be created.
GML:
//All code is In Create Event
function my_func(_x,_y ) constructor{
    // show_debug_message([x,y]);   can't print here any more
    x = _x;
    y = _y;
}

id.my_func(0,0);//nothing happen to the object position
temp = new id.my_func(400,400);
id.my_func(110,110);//nothing happen to the object position
temp = new id.my_func(600,600);
id.my_func(110,110);//nothing happen to the object position
Yes, if add constructor, every "new" struct line is to create the struct while not to move the object's position and can't print (x,y) at entry any more.
But I can't get why these code will excute with out error, and what is happened inner.
 
Last edited:
GML:
//All code is In Create Event
function my_func(_x,_y ) constructor{
    // show_debug_message([x,y]);   can't print here any more
    x = _x;
    y = _y;
}

id.my_func(0,0);//nothing happen to the object position
temp = new id.my_func(400,400);
id.my_func(110,110);//nothing happen to the object position
temp = new id.my_func(600,600);
id.my_func(110,110);//nothing happen to the object position
Yes, if add constructor, every "new" struct line is to create the struct while not to move the object's position and can't print (x,y) at entry any more.
But I can't get why these code will excute with out error, and what is happened inner.
You can print in the constructor, just not before you actually set the variables. Try changing the variables to the underscore versions.
 

Homunculus

Member
Yes, if add constructor, every "new" struct line is to create the struct while not to move the object's position and can't print (x,y) at entry any more.
But I can't get why these code will excute with out error, and what is happened inner.
Not sure why you want a constructor on a function that isn't supposed to create a struct. It's also difficult to get what happens if you call new on a function, but I'm not surprised it doesn't throw an error since constructors at the end of the day are functions.

My guess is that in your lines where you use new, you are in fact calling the function in the instance scope, and therefore changing the x and y position of your instance like calling the function normally. It's a useless info though, it's wrong from the start.
 
GML:
//All code is In Create Event
function my_func(_x,_y ) constructor{
    // show_debug_message([x,y]);   can't print here any more
    x = _x;
    y = _y;
}

id.my_func(0,0);//nothing happen to the object position
temp = new id.my_func(400,400);
id.my_func(110,110);//nothing happen to the object position
temp = new id.my_func(600,600);
id.my_func(110,110);//nothing happen to the object position
Yes, if add constructor, every "new" struct line is to create the struct while not to move the object's position and can't print (x,y) at entry any more.
But I can't get why these code will excute with out error, and what is happened inner.
It's not that difficult...
1) When you new MyFunctionMarkedAsConstructor() you are creating an "instance" and returning it.
2) This "instance" is different from the instances made from objects.. it's called struct (AKA lightweight object instance)
3) As you might imagine inside that struct you can have variables and those are independent from the instance ones.


############### LETS LOOK AT THE IMAGE BELOW #############
Capture.PNG
GML:
 //0) you create an instance of objBase
//1) in the create event you set the x and y (of the instance to 10 and 22)
//2) you create a struct of type MyStruct
//3) this is an individual entity that as nothing to do with the instance
//4) you set variables inside the struct 'a'
//5) the x and y inside the struct are not the same from the instance.
### LETS LOOK AT ANOTHER EXAMPLE WITH CONSTRUCTOR PARAMS ###
Capture2.png
GML:
//0) you create an instance of objBase
//1) in the create event you set the x and y (of the instance to 10 and 22)
//2) you create a struct of type MyStruct and pass (100 and 200 as params)
//3) the struct is created and the 'struct variables' are set
[CONCLUSION] the x and y inside the struct is not the x and y inside the instance :)

[EXTRA]
If you want to change the instance position you need to either:
1) remove the constructor keyword from the function.
OR
2) use other keyword before the x/y variables.

Either way:
  • If the function is marked as a constructor you should NOT call it as a function.
  • If it is NOT a constructor you shoudn't be calling it with new.
 
Last edited:

FrostyCat

Member
GML:
//All code is In Create Event
function my_func(_x,_y ) constructor{
    // show_debug_message([x,y]);   can't print here any more
    x = _x;
    y = _y;
}

id.my_func(0,0);//nothing happen to the object position
temp = new id.my_func(400,400);
id.my_func(110,110);//nothing happen to the object position
temp = new id.my_func(600,600);
id.my_func(110,110);//nothing happen to the object position
Yes, if add constructor, every "new" struct line is to create the struct while not to move the object's position and can't print (x,y) at entry any more.
But I can't get why these code will excute with out error, and what is happened inner.
When you go inside a constructor, all the code inside is run from the perspective of the typed struct being created, not the object instance running the code. If you want your constructor to act on the object instance running the code, it needs an extra parameter for the subject to run with.
GML:
function my_func(_x, _y, _subject) constructor {
    show_debug_message([_subject.x, _subject.y]);
    _subject.x = _x;
    _subject.y = _y;
    ...
}
var temp = new my_func(400, 400, id);
 
One question, maybe for many I will be trivial but ...
Is it possible to insert several constructors in nested data structures? Or would this not make sense?

Furthermore, if I have not misunderstood, with this new update it is possible to use the code by manipulating it with more freedom at a higher level, useful above all for very complex projects and artificial intelligence. With the old version of GameMaker I wanted to be able to recreate a complex and sophisticated artificial intelligence engine but every time I tried and I had to change something (perhaps for my inexperience) I gave up everything ... It seems to me that with this new version it seems like a goal sharper to achieve thanks precisely to the data structures, right? Always sorry for my bad english but I write with my great friend Translator!
 

FrostyCat

Member
One question, maybe for many I will be trivial but ...
Is it possible to insert several constructors in nested data structures? Or would this not make sense?

Furthermore, if I have not misunderstood, with this new update it is possible to use the code by manipulating it with more freedom at a higher level, useful above all for very complex projects and artificial intelligence. With the old version of GameMaker I wanted to be able to recreate a complex and sophisticated artificial intelligence engine but every time I tried and I had to change something (perhaps for my inexperience) I gave up everything ... It seems to me that with this new version it seems like a goal sharper to achieve thanks precisely to the data structures, right? Always sorry for my bad english but I write with my great friend Translator!
It's possible, and it makes perfect sense. This stuff is made to be nested.

An example from a project I released around 3 weeks ago (link):
GML:
var mpdb = new MultipartDataBuilder({
    title: "Twerking Turtle",
    description: "You know what to do with that big fat butt?",
    image: new FilePart(working_directory + "twerking_turtle.gif")
});
var bufferBody = mpdb.getBuffer();
var headers = mpdb.getHeaderMap();
Notice how I've nested a FilePart constructor inside a MultipartDataBuilder constructor.
 
It's possible, and it makes perfect sense. This stuff is made to be nested.

An example from a project I released around 3 weeks ago (link):
GML:
var mpdb = new MultipartDataBuilder({
    title: "Twerking Turtle",
    description: "You know what to do with that big fat butt?",
    image: new FilePart(working_directory + "twerking_turtle.gif")
});
var bufferBody = mpdb.getBuffer();
var headers = mpdb.getHeaderMap();
Notice how I've nested a FilePart constructor inside a MultipartDataBuilder constructor.
Thanks for the answer, I will read your document calmly ... Another question: will it not be possible to run the script anymore? will script_execute be deprecated or will it work the same way with arguments?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Thanks for the answer, I will read your document calmly ... Another question: will it not be possible to run the script anymore? will script_execute be deprecated or will it work the same way with arguments?
script_execute() will continue to work the same way it has been.
Not exactly... script_execute() will still work, but it will work in a bit of a different way depending on context... For legacy projects (ie: projects that have a single script with a single function, AND the function is the same name as the script) then it can be used just as always. However for new projects, you can provide a function name and the arguments for the function instead of the script and use it to call a function (although this is not really the recommended use). You can also call a script that contains functions using it, but I can't really think of a reason why you'd do this since all scripts will be getting run on game start anyway, since scripts are now global scope... (although I am assured there are some edge-case reasons why this might be desirable).
 

Zhanghua

Member
Thank you for the detail explanation
@Homunculus @Rui Rosário
@FrostyCat @xDGameStudios


Then I find a setence in the DOC and say that function has a flag to indicate the constructor or not.
Before using this operator it is important to note that the function given must be flagged as a constructor function otherwise the new operator will not create the struct (the code example below shows this, and for more information.
Althought DOC of "new operator" says that "the new operator will not create the struct " with the none constructor flaged function.
But the DOC of "instanceof" shows more information:
Note that if you pass the function a struct literal (ie: a struct that was created without using a constructor function) then it will simply return the string "struct".
So, In principle, I can't use struct as function or vise versa.
 

TheMagician

Member
However for new projects, you can provide a function name and the arguments for the function instead of the script and use it to call a function (although this is not really the recommended use).
Could you elaborate on what the recommended use is? What would be the correct way to replace this 2.2 line in 2.3 assuming that script_input_mouse is now one of many functions inside a script?
GML:
if (script_exists(script_input_mouse)) script_execute(script_input_mouse);
 

saffeine

Member
could somebody using the beta confirm whether or not a constructor can be set up as an expression as opposed to a declaration, and show how it could be done?
i don't think anybody would have a use for this, as function NewConstructor constructor {} is perfectly fine, but curiosity got the better of me.

an example would be how functions can be declared:
1. function NewFunction() {} ( declaration ).
2. NewFunction = function() {} ( expression ).

with constructors having two keywords in different places, it seems like it isn't possible or just looks messy but still.
again, this has no real use, i'm just curious to know if there is a constructor equivalent of it.

and just as a quick second question: am i right in thinking that functions declared as an expression are stored as instance variables, and functions declared as a declaration are scoped globally?
( additionally, is there a way to store constructors as local / instance variables in this case? )
 
Last edited:

Zhanghua

Member
could somebody using the beta confirm whether or not a constructor can be set up as an expression as opposed to a declaration, and show how it could be done?
i don't think anybody would have a use for this, as function NewConstructor constructor {} is perfectly fine, but curiosity got the better of me.

an example would be how functions can be declared:
1. function NewFunction() {} ( declaration ).
2. NewFunction = function() {} ( expression ).

with constructors having two keywords in different places, it seems like it isn't possible or just looks messy but still.
again, this has no real use, i'm just curious to know if there is a constructor equivalent of it.

and just as a quick second question: am i right in thinking that functions declared as an expression are stored as instance variables, and functions declared as a declaration are scoped globally?
( additionally, is there a way to store constructors as local / instance variables in this case? )
GML:
function demo(a){//it's a function
    show_debug_message(a);
}

m = demo;//m get the reference of demo
show_debug_message( typeof(m) )//print "method",m is a method variable
show_debug_message( m )//print function gml_Script_demo_gml_Object_Object1_Create_0, that's the real name of the function demo.(this function is declare in the Object create event)
m(123);//print 123
//m is not a copy of function demo,just something like function pointer.
//equal to call demo(123)


n = function(){};
show_debug_message( n )//print gml_Script_anon_gml_Object_Object1_Create_0_576_gml_Object_Object1_Create_0,
//here n is just a method variable to hold the anonymous function's reference.
//the name of anonymous  maybe
 
Last edited:

saffeine

Member
GML:
function demo(a){//it's a function
    show_debug_message(a);
}

m = demo;//m get the reference of demo
show_debug_message( typeof(m) )//print "method",m is a method variable
m(123);//print 123
//m is not a copy of function demo,just something like function pointer.
//equal to call demo(123)
that's not the point i was making but i do appreciate the time and effort.
i'm asking whether or not the same thing can be done with constructors instead, and whether or not the references can be made local rather than global.
 

Zhanghua

Member
that's not the point i was making but i do appreciate the time and effort.
i'm asking whether or not the same thing can be done with constructors instead, and whether or not the references can be made local rather than global.
No, don't do that, although it may haven't errors.
The constructor is just to declare a constructor function of struct.
You can use the constructor function to execute like function, but the result will be unpredictable.


GML:
m1 = {
    a:1,
    b:2
}//this is a struct
show_debug_message(m1);//{a:1,b:2}

//you can declare a constructor function
function m_typed() constructor{
    a = 1;
    b = 2;
}

m2 = new m_typed();//here m2 is same to m1.
show_debug_message(m2);//{a:1,b:2}
//m1 is created directly and m2 is created by the constructor function.

show_debug_message(m_typed);//print function gml_Script_m_typed_gml_Object_Object1_Create_0
m = m_typed;
show_debug_message(m);//print function gml_Script_m_typed_gml_Object_Object1_Create_0
m3 = new m();
show_debug_message(m3);//{a:1,b:2}
 
Last edited:

saffeine

Member
No, don't do that, although it may haven't errors.
The constructor is just to declare a constructor function of struct.
You can use the constructor function to execute like function, but the result will be unpredictable.


GML:
m1 = {
    a:1,
    b:2
}//this is a struct

//you can declare a constructor function
function m_typed(){
    a = 1;
    b = 2;
}

m2 = new m_typed();//here m2 is same to m1.

//m1 is created directly and m2 is created by the constructor function.
i'm aware, but what if i wanted to create a constructor local to something else? an example would be like an entity having an inventory ( in this case, multiple ):
GML:
function Entity() constructor {
    function Inventory() constructor {
          return [];
    }

    localInv[0] = new Inventory();
}

newPlayer = new Entity();
newPlayer.localInv[1] = new newPlayer.Inventory();
it might sound impractical, but i can see a lot of uses for something like this. from the example i provided, to a gamepad object ( which i plan to have ), etc.
i'd like to be able to have an Inventory() constructor referenced only within the scope of a struct created via new Entity();.

of course, if i just name my constructors appropriately it should never be an issue, and i don't think other languages support something like this, but i am interested.
( i might be wrong. i'm not 100% sure but i think you can create private constructors in Java. i haven't touched it in a while though so i do doubt my knowledge.
EDIT: i just tried doing something like this in JavaScript which isn't the same as java but i don't have my IDE set up so it's all I had. it didn't work at all because it didn't register as a constructor. )
 
Last edited:

Zhanghua

Member
GML:
function Entity() constructor {
    function Inventory(a) constructor {
          _a = a;//don't do the return cause new operator just make a struct while not the return.
    }

    localInv[0] = new Inventory(0);
}

newPlayer = new Entity();
newPlayer.localInv[1] = new newPlayer.Inventory(1);

show_debug_message(newPlayer.localInv)//[ { _a : 0 },{ _a : 1 } ]
No... you can't do the return stuff
 
Last edited:

saffeine

Member
does it still work if you try to call it from outside the Entity() scope like this:
GML:
function Entity() constructor {
    function Inventory() constructor {
          return [ "Value1", "Value2" ]; // just to return something tangible.
    }

    localInv[0] = new Inventory();
}

newPlayer = new Entity();
newPlayer.localInv[1] = new newPlayer.Inventory();
newPlayer.localInv[2] = new Inventory();

show_debug_message( newPlayer.localInv[0] ); // inside the constructor itself.
show_debug_message( newPlayer.localInv[1] ); // with reference to the new Entity.
show_debug_message( newPlayer.localInv[2] ); // without reference to the new Entity.
i'm interested to see if any of them error, especially the third one.
if so, then i guess it's back to figuring out a decent controller system again 😋
 

Zhanghua

Member
GML:
function Entity() constructor {
    function Inventory(a) constructor {
          _a = a;//don't do the return cause new operator just make a struct while not the return.
    }

    localInv[0] = new Inventory(0);
}

newPlayer = new Entity();
newPlayer.localInv[1] = new newPlayer.Inventory(1);

show_debug_message(newPlayer.localInv)//[ { _a : 0 },{ _a : 1 } ]
@saffeine


the new Inventory() will return the struct which is created by the constructor, while not the return stuff inner it.
You should do this like something above.
 

saffeine

Member
the new Inventory() will return the struct which is created by the constructor, while not the return stuff inner it.
You should do this like something above.
i keep forgetting that constructors don't actually return anything but the struct, my bad.
thanks for testing this stuff out for me, i appreciate it a lot :)
 

Zhanghua

Member
i keep forgetting that constructors don't actually return anything but the struct, my bad.
thanks for testing this stuff out for me, i appreciate it a lot :)
GML:
function Entity() constructor {
    function Inventory(a) constructor {
          _a = a; // just to return something tangible.
    }
    localInv[0] = new Inventory(0);
}


newPlayer = new Entity();
show_debug_message( newPlayer.localInv[0] ); // {_a:0}

newPlayer.localInv[1] = new newPlayer.Inventory(1);// {_a:1}
show_debug_message( newPlayer.localInv[1] ); // with reference to the new Entity.

//Error here cause the Inventory isn't existed in the global or object's scope
newPlayer.localInv[2] = new Inventory();//Variable Object1.Inventory(100132, -2147483648) not set before reading it.
i keep forgetting that constructors don't actually return anything but the struct, my bad.
thanks for testing this stuff out for me, i appreciate it a lot :)

In fact, you can call the constructor function as general function.but don't know when something will be wrong.
The weird thing that I encountered is the scope of function's inner member might change, if you use function as constructor.

i keep forgetting that constructors don't actually return anything but the struct, my bad.
thanks for testing this stuff out for me, i appreciate it a lot :)
GML:
//Bad example.........use constructor as a normal function directly.
//called in Object's Create Event
function Add(a,b) constructor {
    _a = a;
    _b = b;
    return a+b;
}

show_debug_message( Add(1,2) ); //print 3
show_debug_message([id._a,id._b]);//print [ 1,2 ], cause when you use Add as a function, the _a and _b will expand for the outside scope, here is the instance.
i keep forgetting that constructors don't actually return anything but the struct, my bad.
thanks for testing this stuff out for me, i appreciate it a lot :)

GML:
//Another Bad Example.........use a normal function as constructor.
//called in Object's Create Event
function Test(a,b) {
    _a = a;
    _b = b;
}

//scope of Test is the Object
Test(1,2);
show_debug_message([id._a,id._b]);//print [ 1,2 ],

m = new Test(3,4);
//but now, scope of Test change to the m
show_debug_message([id._a,id._b]);//[1,2],
show_debug_message([m._a,m._b]);//[3,4]
Test(5,6);
show_debug_message([id._a,id._b]);//[1,2]
show_debug_message([m._a,m._b]);//[5,6]
 

FrostyCat

Member
Has anyone at YoYo even tried running the HTML5 and Ubuntu exports?

F6 is dead on HTML5 for all projects because of a syntax error in the compiled output:
Code:
SyntaxError: unexpected token: identifier
ReferenceError: GameMaker_Init is not defined
And F5 and F6 are dead on Ubuntu because of an unavoidable problem with Renci SSH:
Code:
pscp Y:\scratchpad_46740C7B_VM\GameAssetsLinux.zip /builds
Renci.SshNet.Common.ScpException: scp: /builds: Is a directory
   at Renci.SshNet.ScpClient.CheckReturnCode(Stream input)
   at Renci.SshNet.ScpClient.UploadFileModeAndName(IChannelSession channel, Stream input, Int64 fileSize, String serverFileName)
   at Renci.SshNet.ScpClient.Upload(FileInfo fileInfo, String path)
   at ..(String , String , Boolean )
   at Igor.LinuxBuilder.Run()
Igor complete.
I've reported the Renci one more than 2 beta releases ago and still nothing has happened.
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
Has anyone at YoYo even tried running the HTML5 and Ubuntu exports?

F6 is dead on HTML5 for all projects because of a syntax error in the compiled output:
Code:
SyntaxError: unexpected token: identifier
ReferenceError: GameMaker_Init is not defined
And F5 and F6 are dead on Ubuntu because of an unavoidable problem with Renci SSH:
Code:
pscp Y:\scratchpad_46740C7B_VM\GameAssetsLinux.zip /builds
Renci.SshNet.Common.ScpException: scp: /builds: Is a directory
   at Renci.SshNet.ScpClient.CheckReturnCode(Stream input)
   at Renci.SshNet.ScpClient.UploadFileModeAndName(IChannelSession channel, Stream input, Int64 fileSize, String serverFileName)
   at Renci.SshNet.ScpClient.Upload(FileInfo fileInfo, String path)
   at ..(String , String , Boolean )
   at Igor.LinuxBuilder.Run()
Igor complete.
I've reported the Renci one more than 2 beta releases ago and still nothing has happened.
The Ubuntu error also looks trivially easy to fix, scp needs the -r flag to copy directories (just like regular cp).
 
Top