WasabiHeat
Member
Recently i've been trying to cut down on the amount of unnecessary objects in my game and one that i've been trying to cut down on is my teleporter objects. I want to make a single teleporter object where each instance of the object will have a "warpID" variable that's set in the room editor. If the player touches an open teleporter they'll be warped to another teleporter object in the same room, so long as it has the same warpID number. I saw that using a combination of a for loop and instance_find is a good way to do something like that, but i'm not entirely sure on how to actually use instance id's to modify an object instance.
This bit of code is in my player object, for when it collides with a teleporter. openPort is just a variable to see if the teleporter the player just touched is actually open (which they all are by default). What i'm mostly struggling with is what to do after var finder is initialized. I just want to check the warpID of the teleporter that was just identified by instance_find and then change the player's position to the new teleporter if the warpID of both teleporters match.
Having said that, I've also heard rumblings that setting up all of my teleporter id's into an array would be an even slicker solution to this problem than using a temporary variable. I'm not sure where and when I would initialize that array or what the advantages actually are though. Even still, i'd mostly like to learn more about instance id's and how they work/can be manipulated and would appreciate any help or resources to let me get to know them better.
GML:
if (other.openPort) {
for (i = 0; i < instance_number(oTeleporter); i += 1)
{
var finder = instance_find(oTeleporter,i);
}
}
Having said that, I've also heard rumblings that setting up all of my teleporter id's into an array would be an even slicker solution to this problem than using a temporary variable. I'm not sure where and when I would initialize that array or what the advantages actually are though. Even still, i'd mostly like to learn more about instance id's and how they work/can be manipulated and would appreciate any help or resources to let me get to know them better.
Last edited: