• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion Asset properties - proposal

gnysek

Member
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?
 

rwkay

YoYo Games Staff
YYG Staff
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
 

Alice

Toolmaker of Bucuresti
Forum Staff
Moderator
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)
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)
 

rwkay

YoYo Games Staff
YYG Staff
@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.
 

gnysek

Member
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:
 

rwkay

YoYo Games Staff
YYG Staff
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

Toolmaker of Bucuresti
Forum Staff
Moderator
@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.
 

rwkay

YoYo Games Staff
YYG Staff
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
 

GMWolf

aka fel666
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).
 

gnysek

Member
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.
 
Top