• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker IDE - use object variable definitions to "link" editor object instances together?

descrubb

Member
So, I decided I wanted to be able to create a sort of "map" that isn't a straight grid. One location might link to tens of other locations. I couldn't think of a way to accomplish this except for creating singular points and then manually linking them together. I have an object keeping track of all the links and drawing lines representing all those links:

Obviously this could get crowded, but for the proof of concept it works.

Next would be the task of setting the data in each of the points for me to export and use as a map in any of my other game projects that need omni-directional navigation free of being locked down to grid based movement with only 8 possible directions.

Well... That part I've already started on and is becoming quite daunting...

SO to my question:

How can I accomplish this same idea just using the IDE? is it even possible?

I've started by adding object points to a room and attempting to expose the other object instances by adding them as a selectable multi-select list item in the variable definitions. Then I go to each point and select from the dropdown which points they will have in their array.

ss-variable definitions.png

Being able to do all of the linking in the editor would take out so much of the work of creating my own ui buttons and having to deal with all the bugginess of my poor coding skills. Creating the framework for creating a map took about 95% of the time. generating a map like this is really out of the scope of what I'm trying to accomplish as what seems like should be a simple task.

Anyways... thoughts?
 

Niften

Member
You could create some controller object and have it contain a list linked_points - from there, you would add the instances that are linked together (in the order that you want) and then iterate through each point in the controller object to draw it.

P.S. I'm not sure if you can change the order or not, I've never worked with the variable definitions window.
 

Roldy

Member
So, I decided I wanted to be able to create a sort of "map" that isn't a straight grid. One location might link to tens of other locations. I couldn't think of a way to accomplish this except for creating singular points and then manually linking them together. I have an object keeping track of all the links and drawing lines representing all those links:

Obviously this could get crowded, but for the proof of concept it works.

Next would be the task of setting the data in each of the points for me to export and use as a map in any of my other game projects that need omni-directional navigation free of being locked down to grid based movement with only 8 possible directions.

Well... That part I've already started on and is becoming quite daunting...

SO to my question:

How can I accomplish this same idea just using the IDE? is it even possible?

I've started by adding object points to a room and attempting to expose the other object instances by adding them as a selectable multi-select list item in the variable definitions. Then I go to each point and select from the dropdown which points they will have in their array.

View attachment 32458

Being able to do all of the linking in the editor would take out so much of the work of creating my own ui buttons and having to deal with all the bugginess of my poor coding skills. Creating the framework for creating a map took about 95% of the time. generating a map like this is really out of the scope of what I'm trying to accomplish as what seems like should be a simple task.

Anyways... thoughts?
Seems like that would work.

However, couple things to keep in mind:

  • multiselect link list actually end up being arrays
  • instance names seems kinda useless
  • the linked list values are expressions

Since they are expressions you could make their values:

intance_find( map_point_obj, 0)
intance_find( map_point_obj, 1)
intance_find( map_point_obj, 2)
intance_find( map_point_obj, 3)
intance_find( map_point_obj, 4)
etc..

But you would have to know which of index is which instance. Now I don't think the instance name gives you enough info to know which instance in the editor is in which object index slot.

You could assume their creation order will determine that, but I think that would be considered "undocumented behavior".

I have no idea if you can even get the instance name at runtime.

However you could make a script that could find an identifier for you:

So you give the object two variable definitions:

  1. linked list
  2. point_name
For each instance of map_point_obj you set point_name to whatever you like

Then you have a script:
GML:
/// find_map_point( _name)

var _name = argument0;
var _instanceCount = instance_number( map_point_obj );

for (var _i = 0; _i < _instanceCount; _i++) {

    var _mapPointInstance = instance_find( map_point_obj, _i);

    if ( _mapPointInstnace.point_name == _name) {

        return _mapPointInstance;

    }

}

return undefined;
And for the linked list varaible definition you could set them to be:

  • find_map_point("point_name1")
  • find_map_point("final_room")
  • find_map_point("boss_fight")
  • find_map_point("whatever you want to name your points")
  • etc

And then for each map point instance select which points they are linked to.

Try that and see if it works.
 
Last edited:

descrubb

Member
You could create some controller object and have it contain a list linked_points - from there, you would add the instances that are linked together (in the order that you want) and then iterate through each point in the controller object to draw it.

P.S. I'm not sure if you can change the order or not, I've never worked with the variable definitions window.
That's actually exactly what I'm doing right now. The map points and dotted lines you see are actually just a visual representation of the code. The hard part is where I have to export the data points and links and import them into another project.
 

descrubb

Member
However, couple things to keep in mind:

  • multiselect link list actually end up being arrays
  • instance names seems kinda useless
  • the linked list values are expressions
I did know about those except the last, that could end up useful later...


So you give the object two variable definitions:

  1. linked list
  2. point_name
For each instance of map_point_obj you set point_name to whatever you like

Then you have a script:
GML:
/// find_map_point( _name)

var _name = argument0;
var _instanceCount = instance_number( map_point_obj );

for (var _i = 0; _i < _instanceCount; _i++) {

    var _mapPointInstance = instance_find( map_point_obj, _i);

    if ( _mapPointInstnace.point_name == _name) {

        return _mapPointInstance;

    }

}

return undefined;
And for the linked list varaible definition you could set them to be:

  • find_map_point("point_name1")
  • find_map_point("final_room")
  • find_map_point("boss_fight")
  • find_map_point("whatever you want to name your points")
  • etc

And then for each map point instance select which points they are linked to.

Try that and see if it works.
I could see that working great... imagine 300 map points though, and that's just for a single application... I'd like to be able to just throw this stuff together and not have to do manually call every name I'm looking to access from another point. That stuff takes up quite a good portion of what could be time working on the content itself.

I could probably end up spending the same amount of time developing this tool and get a better result than I would from fiddling with the IDE...
 

Roldy

Member
I did know about those except the last, that could end up useful later...




I could see that working great... imagine 300 map points though, and that's just for a single application... I'd like to be able to just throw this stuff together and not have to do manually call every name I'm looking to access from another point. That stuff takes up quite a good portion of what could be time working on the content itself.

I could probably end up spending the same amount of time developing this tool and get a better result than I would from fiddling with the IDE...
I agree. The IDE isn't setup for it.
 

TailBit

Member
I made something like this when I tried to make a mario party game, but I wanted it somehow automatic, so in the create event I had them scan for the nearest points to automatically add to its array, I also made a trail of objects between them.

all of them had the same parent object o_path, and would just try to connect to the 2 o_path in range

my o_tile objects (like your green ones) connected to the all nearby o_path_start and o_path_end (so usually 2-3 connections)

when standing on o_tile then I only allowed to choose between the paths leading to a o_path_start

when going between the points you always remember the o_tile you came from, so when you reach the next o_tile then you have it target the one that isn't going to the tile you came from

ofc .. this made it so that I had to be very careful where I placed them, to avoid them connecting into a strange cluster, so not that ideally.

if I was smart then I would had done a digger method, having one o_tile be a o_start_tile, connecting up a path that starts of at a o_path_start, and when at a o_path only connect to o_path_start before switching to o_path, adding them to a ds_list as you dig the way around .. til all the points have been found
 
Last edited:
I've got linked wormholes in the game I'm working on right now (as well as a few other things, but the main linked instances are wormholes). You can place them in the map editor I built and then use those maps in the game. I already knew that linking instance ID's wasn't going to work, as they will be different each time the level is loaded/edited/whatever, and you obviously can't just use object indices as those will essentially link randomly. The method I used was to save the x and y position of the linked instance, instead of saving the instance itself. So in my example, I place two wormholes, they become linked, so I save the position of the linked wormhole in a map associated with each wormhole.

This way, whenever a wormhole gets created, it can check its associated map and see if it has a linked position in saved in there. If it does, it waits until all the wormholes have been spawned and then simply runs an instance_position(linked_x,linked_y,obj_wormhole) to get the instance ID of the wormhole it is linked to. You could generalise it more (and I did, saving linked object types as well, so I can have anything linked to anything if I wanted) and you end up with a pretty robust save/spawn system that allows linked instances. If you build your own map editor, you can automatically save a bunch of this stuff in whatever format you like (I find JSON easiest to deal with, but there's a few different formats you could use) and make creating/loading levels much easier.
 

Yal

šŸ§ *penguin noises*
GMC Elder
How about creating "map link" objects that are just straight lines, and then stretching/rotating them so they overlap the two map markers they connect? On their collision event with map markers, they put their IDs in a list; after one step (so they've had a chance to collide with both markers they connect) they tell the markers involved that they are connected. In their draw event, once those steps are done, it draws a pretty line between the map markers (if both are unlocked).
 

descrubb

Member
I made something like this when I tried to make a mario party game, but I wanted it somehow automatic, so in the create event I had them scan for the nearest points to automatically add to its array, I also made a trail of objects between them.

all of them had the same parent object o_path, and would just try to connect to the 2 o_path in range

my o_tile objects (like your green ones) connected to the all nearby o_path_start and o_path_end (so usually 2-3 connections)

when standing on o_tile then I only allowed to choose between the paths leading to a o_path_start

when going between the points you always remember the o_tile you came from, so when you reach the next o_tile then you have it target the one that isn't going to the tile you came from

ofc .. this made it so that I had to be very careful where I placed them, to avoid them connecting into a strange cluster, so not that ideally.

if I was smart then I would had done a digger method, having one o_tile be a o_start_tile, connecting up a path that starts of at a o_path_start, and when at a o_path only connect to o_path_start before switching to o_path, adding them to a ds_list as you dig the way around .. til all the points have been found
This is good, however I need specific points linked to other specific points hand crafted. There would be no way to have it "scan" and have the links come out correctly every time unless I had a specific naming convention or as you said be very careful with where I placed them.

Yal also has a good idea for an IDE hybrid way of doing things that might take down the workload.
 

descrubb

Member
I've got linked wormholes in the game I'm working on right now (as well as a few other things, but the main linked instances are wormholes). You can place them in the map editor I built and then use those maps in the game. I already knew that linking instance ID's wasn't going to work, as they will be different each time the level is loaded/edited/whatever, and you obviously can't just use object indices as those will essentially link randomly. The method I used was to save the x and y position of the linked instance, instead of saving the instance itself. So in my example, I place two wormholes, they become linked, so I save the position of the linked wormhole in a map associated with each wormhole.

This way, whenever a wormhole gets created, it can check its associated map and see if it has a linked position in saved in there. If it does, it waits until all the wormholes have been spawned and then simply runs an instance_position(linked_x,linked_y,obj_wormhole) to get the instance ID of the wormhole it is linked to. You could generalise it more (and I did, saving linked object types as well, so I can have anything linked to anything if I wanted) and you end up with a pretty robust save/spawn system that allows linked instances. If you build your own map editor, you can automatically save a bunch of this stuff in whatever format you like (I find JSON easiest to deal with, but there's a few different formats you could use) and make creating/loading levels much easier.
Actually... I think this will be really useful for exporting the data for another application. Thank you!
 
Top