Discussion Asset properties - proposal

Discussion in 'GameMaker Studio 2 Community Tech Support' started by gnysek, Nov 23, 2016.

  1. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,342
    Currently, if you want to get instance variable, you use:

    id.property

    But if you want to get asset property, like sprite width, you need to write sprite_get_width(sprite_name)

    I don't see, why GM:S shouldn't allow as alternate (still keeping old way):

    sprite_name.width
    sprite_name.height
    sprite_name.name
    sprite_name.number
    sprite_name.xoffset
    sprite_name.yoffset
    sprite_name.bbox_bottom
    sprite_name.bbox_left
    sprite_name.bbox_right
    sprite_name.bbox_top
    sprite_name.tpe
    sprite_name.texture
    sprite_name.uvs


    And change above code to sprite_get_xxx() function on compile name (of course as long, as sprite_name is valid resource name and have property after dot)
    I propose same for other resources, with properties they can have.

    The only problem here are objects, cause for now, you can get variables from existing instance (usually from the one created as first in current room) using object_name.property (like object_name.solid), so there can be different syntax for what I'm proposing:

    @resource_name.proprety
    ~resource_name.property
    resource_name->property
    ...


    Anybody interested, or you don't like the idea?
     
    JimmyBG likes this.
  2. rwkay

    rwkay YoYo Games Staff YYG Staff

    Joined:
    Apr 12, 2016
    Posts:
    1,049
    We are heading towards this type of syntax but it is going to take a while as the internals change to prepare the way... so no definitive time frame (depends how much time I get to work on it)

    The first step towards this is making the data structures and resource types into reference values and not index numbers (as they are just now)

    Russell
     
  3. JimmyBG

    JimmyBG Member

    Joined:
    Jun 22, 2016
    Posts:
    55
    This would be great :D
     
  4. Alice

    Alice Toolmaker of Bucuresti Forum Staff Moderator

    Joined:
    Jun 20, 2016
    Posts:
    819
    Just to make sure I don't mistake anything...

    ...does it mean we will finally be able to tell a map apart from a list and sprite apart from object and room apart from a regular integer, given the reference value alone? I would totally dig it if that happened!

    Oh, and related thing - right now assets of specific type can be enumerated using something like:
    Code:
    for (var i = 0; sprite_exists(i); i++) { /* do whatever with each sprite */ }
    If the assets would no longer use indices, would there be an alternate method of enumerating them?

    (personally, I don't really use it at the moment, but some people might find it useful for various purposes)
     
  5. rwkay

    rwkay YoYo Games Staff YYG Staff

    Joined:
    Apr 12, 2016
    Posts:
    1,049
    @Alice - yes it would mean that we can finally tell the difference between the data structure types and the resource types (they would no longer be just numbers) and Yes one of the issues would be having a way of enumerating them, but I think type safety is the better way to go.
     
    stainedofmind and Alice like this.
  6. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,342
    So, it would be possible to write: is_sprite(sprite_name); while now sprite_name is just an number from 0 to n, where n is position in resource tree. Love it! :bunny:
     
  7. rwkay

    rwkay YoYo Games Staff YYG Staff

    Joined:
    Apr 12, 2016
    Posts:
    1,049
    actually you will be able to do typeof(sprite_name) and it would return "sprite"

    Actually you can do typeof() now and it will return a string, I had forgotten that was already added.

    Russell
     
    Alice likes this.
  8. Alice

    Alice Toolmaker of Bucuresti Forum Staff Moderator

    Joined:
    Jun 20, 2016
    Posts:
    819
    @rwkay: Ah, there is "typeof" indeed! Sweet, seems like something to switch over when needed.

    Got this so far:
    Code:
    var arr;
    arr[0] = 0;
    arr[1] = 1;
    
    var arr2;
    arr2[0, 0] = 0;
    arr2[0, 1] = 1;
    arr2[1, 0] = 0;
    arr2[1, 1] = 1;
    
    show_debug_message(typeof(ds_map_create()));    // prints "number"
    show_debug_message(typeof(object_0));    // prints "number"
    show_debug_message(typeof(room0));    // prints "number"
    show_debug_message(typeof("stuff"));    // prints "string"
    show_debug_message(typeof(undefined));    // prints "undefined"
    show_debug_message(typeof(arr));    // prints "array"
    show_debug_message(typeof(arr2));    // prints "array"
    I take when the type system gets the overhaul, the map/object/room will instead get their own types instead of generic "number"?

    By the way, what about object instances? Will they have "instance" typeof, or maybe it'll be named after their object? I guess the former might be easier to handle, since if you can tell something is an object instance, you can then switch on its object_index; and if you want just to tell apart object from instances (or whatever else), you could just check for typeof(thing) == "instance".

    Oh, also, will 1D and 2D array types always return "array", or maybe there will be some distinction about them? As @gnysek mentioned in another thread, an ability to tell the two apart would be helpful in some cases.
     
  9. rwkay

    rwkay YoYo Games Staff YYG Staff

    Joined:
    Apr 12, 2016
    Posts:
    1,049
    Yes when references come in the data structures and resources will all get their own return string from typeof so you can make a distinction.

    Part of the array overhaul will be that 2D arrays will effectively disappear every array will be 1D and the current 2D syntax a[0,1] will be equivalent to a[0][1] this will cause some issues with the array_ functions for getting lengths but I think it will be worth it over all.

    Russell
     
    MaddeMichael likes this.
  10. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,496
    If we get propper types everywhere, I still hope a way of getting a list of asses will be built in. Its quite usefull to be able to scan all script and dynamically allocate them. (At least, untill GM gets classes, annotations and interfaces).
     
  11. DukeSoft

    DukeSoft Member

    Joined:
    Jun 20, 2016
    Posts:
    799
    Sweet! One step closer to a proper OOP language :)
     
  12. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,496
    Actually, most languages, OOP or not have types....
    oh, and whilst we are talking about all this: Namespacing please :)
     
    DukeSoft likes this.
  13. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,342
    I won't cry after 2D arrays, I wanted to remove them from my game, but when cannot read as a[0][1][2][....] it's not yet worth.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice