Pages: 1 2 3 »
  Print  
Author Topic: GML  (Read 27259 times)
Offline (Unknown gender) luiscubal
Posted on: September 04, 2010, 09:47:34 am
Member
Joined: Jun 2009
Posts: 452

View Profile Email
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
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: September 04, 2010, 11:09:55 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Most of them have separate id's, but they are connected in one place or another. For example, sprites, fonts and background all have separate id's, but their texture id's are in one list. So adding one sprite, one background and one font, would make a texture list of 3. So every resource has its own id's.
Logged
Offline (Male) Brett
Reply #2 Posted on: September 04, 2010, 11:57:14 am

Member
Location: Canada!
Joined: Aug 2010
Posts: 25

View Profile Email
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
Offline (Female) IsmAvatar
Reply #3 Posted on: September 04, 2010, 12:19:57 pm

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
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
Offline (Unknown gender) TheExDeus
Reply #4 Posted on: September 04, 2010, 12:26:12 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
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
Offline (Unknown gender) luiscubal
Reply #5 Posted on: September 04, 2010, 12:34:33 pm
Member
Joined: Jun 2009
Posts: 452

View Profile Email
@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
Offline (Male) Josh @ Dreamland
Reply #6 Posted on: September 04, 2010, 12:42:57 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
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
Offline (Unknown gender) TheExDeus
Reply #7 Posted on: September 04, 2010, 01:01:07 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
@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.

Quote
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.

Quote
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:
Quote
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
Offline (Unknown gender) luiscubal
Reply #8 Posted on: September 04, 2010, 01:14:04 pm
Member
Joined: Jun 2009
Posts: 452

View Profile Email
Another thing: what is the "then" keyword for? Is it completely useless or is there a use-case for it?
Logged
Offline (Unknown gender) TheExDeus
Reply #9 Posted on: September 04, 2010, 01:23:02 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Shouldn't you ask these questions in GMC?

Anyway, "then" is used in situations like:
Code: [Select]
if something=true then do_somethingNormally thou, you should write this code as:
Code: [Select]
if (something==true){
do_something;
}
Basicly, its just one of the syntax possibilities by gamemaker. "then" I think comes from visual basic, and maybe from somewhere else as well.
« Last Edit: September 04, 2010, 01:24:41 pm by HaRRiKiRi » Logged
Offline (Female) IsmAvatar
Reply #10 Posted on: September 04, 2010, 01:46:18 pm

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
Quote
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)

Quote
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:
Code: [Select]
#define then
Logged
Offline (Unknown gender) The 11th plague of Egypt
Reply #11 Posted on: September 04, 2010, 03:28:06 pm
Member
Joined: Dec 2009
Posts: 274

View Profile
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
Offline (Male) Brett
Reply #12 Posted on: September 04, 2010, 03:49:20 pm

Member
Location: Canada!
Joined: Aug 2010
Posts: 25

View Profile Email
@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
Offline (Female) IsmAvatar
Reply #13 Posted on: September 04, 2010, 04:05:18 pm

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 877

View Profile Email
Quote
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.
No, it's erroring because ds_lists (and other data structures) are not saved, and thus, when you load and try to access your old ds_list, it is now gone. According to the GM Manual in the section for Data Structures (which you've clearly taken the time to read):
Quote
Please note that data structures and their content are not saved when you save the game using the actions or functions for that. If you use data structures and want to allow for saves you have to create your own mechanims for that.
Logged
Offline (Unknown gender) The 11th plague of Egypt
Reply #14 Posted on: September 04, 2010, 05:09:41 pm
Member
Joined: Dec 2009
Posts: 274

View Profile
Quote
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.
No, it's erroring because ds_lists (and other data structures) are not saved, and thus, when you load and try to access your old ds_list, it is now gone. According to the GM Manual in the section for Data Structures (which you've clearly taken the time to read):
Quote
Please note that data structures and their content are not saved when you save the game using the actions or functions for that. If you use data structures and want to allow for saves you have to create your own mechanims for that.


NOOOOOOOOOOOOOOO!!!!



Now I have to make my save system for that too?!
« Last Edit: September 04, 2010, 05:12:00 pm by The 11th plague of Egypt » Logged
Pages: 1 2 3 »
  Print