luiscubal
|
|
Posted on: September 04, 2010, 09:47:34 am |
|
|
Joined: Jun 2009
Posts: 452
|
In my understanding, GML only has a two data types: strings and reals. Most variables, such as rooms, objects, etc. are in fact IDs(reals). surface_create does not return a surface, but rather the ID of a surface. The same applies to stacks, etc.
I'm curious about something in the ID system. Are all IDs completely unique or just unique to that data type? (there can be no more than one single stack with any given ID, but can a stack and a queue have the same ID? Same to instances, objects, etc.)
|
|
|
Logged
|
|
|
|
|
Brett
|
|
Reply #2 Posted on: September 04, 2010, 11:57:14 am |
|
|
Location: Canada! Joined: Aug 2010
Posts: 25
|
The id system starts objects with the id of 100,000 and tiles with 10,000,000. I honestly Don't know if they overlap or not, but they're spaced huge distances apart so that your game shouldn't overlap anyways (9,900,000 objects? Good luck.) You could write a simple loop to test this, however if you were worrying about overlapping - don't. I don't know what comes before objects, but I imagine that sprites, backgrounds, rooms and sounds are all below 100,000.
|
|
|
Logged
|
GML Programmer Since 2005, C++ Programmer Since 2009
|
|
|
IsmAvatar
|
|
Reply #3 Posted on: September 04, 2010, 12:19:57 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
Actually objects start at 0. Instances start at 100,000. Rooms start at 0, etc. If you create a new game, and add 1 of every resource (Sprite, Object, Room, etc), they will all have ID 0. It distinguishes them because you would never use them interchangeably in a function. For instance, it wouldn't make sense to give anything but a sprite to draw_sprite. Likewise, for functions which *could* use them interchangeably, such as creating textures, instead it has different functions for each resource type. ds_list also starts at 0, because it would never make sense for you to use it interchangeably with another resource. I don't know why tile IDs start at 10m, but instance IDs have to be separate from resource IDs, because in-code, you may reference an object's variables (e.g. object0.x) or an instance's variables (myInstance.x), which is interchangeable code with completely different expected results.
|
|
« Last Edit: September 04, 2010, 12:23:16 pm by IsmAvatar »
|
Logged
|
|
|
|
TheExDeus
|
|
Reply #4 Posted on: September 04, 2010, 12:26:12 pm |
|
|
Joined: Apr 2008
Posts: 1860
|
The id system starts objects with the id of 100,000 and tiles with 10,000,000. I honestly Don't know if they overlap or not, but they're spaced huge distances apart so that your game shouldn't overlap anyways (9,900,000 objects? Good luck.) You could write a simple loop to test this, however if you were worrying about overlapping - don't. I don't know what comes before objects, but I imagine that sprites, backgrounds, rooms and sounds are all below 100,000. You are thinking instance id, but I think he means resource id. Resource id's are all in different lists and start at 0, and are dependent on the resource lists in the program itself. So if you make 10 backgrounds, then delete first 9 of them, then the id of the remaining one will still be 10. So these id's can match. Thou as I mentioned before, texture ids are in one list, but as it is created on runtime (and can't be overwritten by any function), then you should not have two matching ids ever. When you run your game the texture id list is at first populated by backgrounds, and then sprites and their subimages.
|
|
|
Logged
|
|
|
|
luiscubal
|
|
Reply #5 Posted on: September 04, 2010, 12:34:33 pm |
|
|
Joined: Jun 2009
Posts: 452
|
@HaRRiKiRi Wait, then Game Maker stores textures separately from sprites and tilesets, and just links these resources to it? Like some kind of implicit invisible resource? I always thought images were "embedded" in the sprite. Is the texture ID used by any function of GML(as an argument)?
EDIT: Some more questions. If I create 10 background, delete the first 9, and then create another background, which will be the ID?
Also, a different kind of problem. In GML, I can draw text even without having fonts(it uses some kind of "default font"). After using draw_set_font, how can I reset the font to the default one?
|
|
« Last Edit: September 04, 2010, 12:37:31 pm by luiscubal »
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #6 Posted on: September 04, 2010, 12:42:57 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Most of this has been said by now, but I'll reiterate and ad lib. I'm not sure where Brett got the idea that tile IDs start at 1,000,000... I believe that may be where tile depth starts.
Anyway, resources (sprites, scripts, objects, etc) start at zero and never reset under normal GM situations. Ism added a function to LGM that can defragment them, but basically, the first resource you create is zero, and any resource after that will just keep counting.
Based on the idea that a game will never have gone through 100000 objects, instance IDs start at 100001. Each instance placed in a room has a "hard-coded" (tongue and cheek in a runner) ID. This means that no matter how many times you visit the room, the instances in there at load time will be given the same ID.
From there, created instances use the same methodology as normal resources; adding constantly to the current highest ID.
ds_stacks, lists, maps... files, surfaces, etc., are all given the same system.
As far as GM is concerned, object0 == sprite0 == instance0-100000 == surface0 == file0 == list0.
This was all just Mark's method of removing pointers.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
TheExDeus
|
|
Reply #7 Posted on: September 04, 2010, 01:01:07 pm |
|
|
Joined: Apr 2008
Posts: 1860
|
@HaRRiKiRi Wait, then Game Maker stores textures separately from sprites and tilesets, and just links these resources to it? Like some kind of implicit invisible resource? I always thought images were "embedded" in the sprite. Is the texture ID used by any function of GML(as an argument)? Sprite has several attributes like origin, collision mask etc., and so textures (the sprite image itself) are separate, but I guess one of the sprites attributes is texture id, so it knows what to draw. Texture id is only used when drawing primitives, and so functions like sprite_get_texture and background_get_texture exists. EDIT: Some more questions. If I create 10 background, delete the first 9, and then create another background, which will be the ID? 10. Because you would of deleted background 0-8 and the number 9 would remain. And when you add another background then it would be 10. Also, a different kind of problem. In GML, I can draw text even without having fonts(it uses some kind of "default font"). After using draw_set_font, how can I reset the font to the default one? The default GM font is -1. So draw_set_font(-1) does it. edit: As far as GM is concerned, object0 == sprite0 == instance0-100000 == surface0 == file0 == list0.
This was all just Mark's method of removing pointers. Yeah, and it allows some cool but useless things. Like draw_sprite(object0,x,y) or instance_create(x,y,sprite0).
|
|
« Last Edit: September 04, 2010, 01:04:18 pm by HaRRiKiRi »
|
Logged
|
|
|
|
|
|
IsmAvatar
|
|
Reply #10 Posted on: September 04, 2010, 01:46:18 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
I'm not sure where Brett got the idea that tile IDs start at 1,000,000... I believe that may be where tile depth starts. I believe he's actually correct. Tile IDs start with 1,000,000. This is the way I have documented them, and this is the way LGM handles them (with the exception of defragging prior to r453, due to a bug) Another thing: what is the "then" keyword for? Is it completely useless or is there a use-case for it? I'm not aware of any use-case for it. As far as I'm aware, it's basically just to make the syntax compatible with other languages like BASIC (including Q-BASIC and VisualBasic) and Pascal. As far as ENIGMA is concerned, I'm sure it is defined thusly: #define then
|
|
|
Logged
|
|
|
|
The 11th plague of Egypt
|
|
Reply #11 Posted on: September 04, 2010, 03:28:06 pm |
|
|
Joined: Dec 2009
Posts: 274
|
Each instance placed in a room has a "hard-coded" (tongue and cheek in a runner) ID. This means that no matter how many times you visit the room, the instances in there at load time will be given the same ID
Damn it! Is that why the save system goes nuts when you load instances created outside the room editor? I've seen it trow me errors when I load objects with lists inside. I just don't know ehat the heck is going on inside there. GM's too obscure. I have to make all kind of backflips to write a simple editor which saves the position of instances inside a .txt file. Anyway, soon you'll see my solution to RTS and FPS collisions. No sprites involved.
|
|
« Last Edit: September 04, 2010, 03:30:58 pm by The 11th plague of Egypt »
|
Logged
|
|
|
|
Brett
|
|
Reply #12 Posted on: September 04, 2010, 03:49:20 pm |
|
|
Location: Canada! Joined: Aug 2010
Posts: 25
|
@Josh I got the idea that tile id's start at 10m because GM says so. Create a background, add it as a tile and highlight it. At the bottom of the editor, it will say it's X,Y, Depth and ID. The id's start at 10m.
@Ism Tile id's start at 10m, not 1m.
And I didn't know that the sprites/backgrounds were stored in seperate lists. (Until I thought about it anyways).
Also, agreeing with flexaplex, I think that he started the tile instances at 10m because both objects (instances) and tiles are stored in the same list. This would make sense, as they have many things in common.
|
|
|
Logged
|
GML Programmer Since 2005, C++ Programmer Since 2009
|
|
|
|
|
|