• 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 [Proposal] named instances info getting

gnysek

Member
Since GM:S 1.x and in GMS2 too, we can set name for instances placed in room editor. As they were numbered from 1000000 up in pre-GMS, they now are usually named "inst_XXXXX" where XXXX is a hex number.

Later on, you can use this variable inside code, since in fact inst_XXXX constant is just an instance id.

But since you can rename them, instead of "inst_A02FBDA6" you can have "teleporter_north_in_room_city".

Would be great, if we can access information about room data for all instances placed in room editor.
From what I remember, instance id is unique for whole game (every instance id is +1 to the last one, even if some were destroyed) and there's no duplicates.

My proposal is:

Code:
room_get_instance_x(instanceId); // returns initial x-coordinate of instance with this ID
room_get_instance_y(instanceId); 
room_get_instance_room(instanceId); // returns in which room this instance is placed
That would be useful for games in which you teleport between rooms forth and backward, so you can start in different places, but currently you cannot access x/y position of instance in another room (as long as it wasn't persistent), so you need to hardcode positions.

For now constants instead of id's are useful only in same room.
 

Jobo

Member
GMC Elder
Code:
with(instanceId) {
    var _x = xstart;
    var _y = ystart;
    var _room = room; // it's just the room we're currently in
}
You can't get information about an instance when it doesn't exist, and nor should you need to. If you want to go to the position of an instance in room A, go to room A and then jump to that position. There's no need to get the position BEFORE going to the room... And since you placed the instance, you already know what room it's in. If that's not enough for you, keep track of it manually with a look-up script room_get_instance_room(instanceId) that you can easily write yourself.

Personally I don't see any useful cases for this... And your use case of teleportation is absolutely not true. This is incredibly easy to do.... also without hacky things like instance IDs...
 

gnysek

Member
@Jobo: it doesn't work for instances in another room. I talking here about getting data about instances in whole game, reading a room-instance list, defined in room editor in IDE, so their state on game compile.
 

gnysek

Member
To get property you set in IDE. Same as object_get_solid() and others, which gives you what you defined before compiling, not what currently instance have set.
 
Or you could do something like this:

Code:
// object creation code; add to ds_list
object_original_x[| instance_id] = x;
So on and so forth.
 

Jobo

Member
GMC Elder
I ask again... Why? I know what ("to get property you set in IDE"), but you haven't said why you think you need this.
 

gnysek

Member
I said. I have a game, in which you can enter end exit from room using various entries, and I need to manually give all X and Y where to teleport, and when I move any "teleport" object, I need to edit it manually again, while this way, I could just write:

Code:
// creation code of instance inst_B89CB76A5
dest = inst_A02FBDA6;
Code:
// colllision event between teleporter and player
global.destination = dest;
global.destination_x = room_get_instance_x(dest) + lengthdir_x(100, point_direction(x,y obj_hero.x, obj_hero.y));
global.destination_y = room_get_instance_y(dest) + lengthdir_y(100, point_direction(x,y obj_hero.x, obj_hero.y));
room_goto( room_get_instance_room(dest) );
Code:
// room start event
instance_create_depth( global.destination_x, global.destination_y, obj_hero, 0);
 

Jobo

Member
GMC Elder
And your use case of teleportation is absolutely not true. This is incredibly easy to do.... also without hacky things like instance IDs...
Make a ds_map, give two teleporters in different rooms the same key, put the key into a global variable before leaving the room and when entering the new room look up the teleporter that associates itself with that key - then go to its x and y.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I said. I have a game, in which you can enter end exit from room using various entries, and I need to manually give all X and Y where to teleport, and when I move any "teleport" object, I need to edit it manually again, while this way, I could just write:

Code:
// creation code of instance inst_B89CB76A5
dest = inst_A02FBDA6;
Code:
// colllision event between teleporter and player
global.destination = dest;
global.destination_x = room_get_instance_x(dest) + lengthdir_x(100, point_direction(x,y obj_hero.x, obj_hero.y));
global.destination_y = room_get_instance_y(dest) + lengthdir_y(100, point_direction(x,y obj_hero.x, obj_hero.y));
room_goto( room_get_instance_room(dest) );
Code:
// room start event
instance_create_depth( global.destination_x, global.destination_y, obj_hero, 0);
Would it have been easier to instead store destination object and direction?

Code:
// creation code of instance inst_B89CB76A5
dest = inst_A02FBDA6;
droom = rm_some; // you probably know which one, as you were the one to place the thing in it
Code:
// colllision event between teleporter and player
global.destination = dest;
global.destination_dir = point_direction(x,y obj_hero.x, obj_hero.y);
room_goto( room_get_instance_room(dest) );
Code:
// room start event
instance_create_depth(
    global.destination.x + lengthdir_x(100, global.destination_dir),
    global.destination.y + lengthdir_y(100, global.destination_dir),
    obj_hero, 0);
Given sufficient demand, there would be also a possibility of producing an extension that would read the game's "WAD file" to extract any information about any room, but, obviously, it requires some file format investigations.
 

Jobo

Member
GMC Elder
You really should not be hard-coding instance ids. See my previous post... It is dead simple.
 

gnysek

Member
You really should not be hard-coding instance ids. See my previous post... It is dead simple.
But named instances were added especially for that! Otherwise we would still see 10000000 and up in room editor as ID. I even got a talk back in 2012 with @rwkay about this, that you can rename instance to what you want, to later reference it in code by constant given in room editor.

If I shouldn't hardcode instance ids, for what would GMS create hundreds of constants in room editor and even have working syntax coloring in code editor for this feature (for both GM:S1 and GM:S)? Wouldn't that feature be removed if I shouldn't hardcode using those contants ?

OK, I can agree, that in what I proposed, I can check for X/Y after going into room, but still, it would be good to have possibility to read room properties (as @YellowAfterlife said, from WAD file, but why not directly from code then, instead of hacking?).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
But named instances were added especially for that! Otherwise we would still see 10000000 and up in room editor as ID. I even got a talk back in 2012 with @rwkay about this, that you can rename instance to what you want, to later reference it in code by constant given in room editor.
Yep, this is true. There is absolutely nothing wrong with targeting an instance name in your code. It's in the IDE and so it's in the game and can be accessed (when in the same room). I do agree though that I can't see much point in what's being requested though...
 
Top