S
SayBaconOneMoreTime
Guest
Hi there:
So I'm working on a top down game. More specifically, I'm working on a cutscene system for a top down game. Recently, I discovered one of the worst ways to handle top down game cutscenes is to run code in a with() statement that just performs an action in the instance that needs to animate for the cutscene. The problems with this are (A) you can't be sure of whether an instance of the object exists- this can be alleviated by calling instance_exists() or whatever that function is, but that's rather cumbersome, and (B) there might be more than one instance of an object in a room, meaning the code would be run in every instance, which could be desirable in some circumstances, but most of the time not.
The system I have worked out in my brain to set up to alleviate this would have a persistent object called obj_actor or something like that which contains a DS map. The map would have a height of three, zero being ID of the instance in the grid, one being whether the instance is currently active or not, and two being the ID of the script being run inside of the instance. Each x coordinate would represent one actor. I would set up an enum of values to correspond with this system of x coordinates. Since, to my knowledge, there is no real way to access the length of an enum in GMS2 (correct me if I'm wrong), I would just put a variable in the enum called "len" or something as the very last variable in the enum and pass it in for the width when creating the grid so that every actor defined in the enum has a spot. I thought about using a map with a string for different actors and the id as a value, but the more I mulled that over in my head, the more complicated it got, and I decided using an enum would just be easier, even though the idea of creating actors and deleting them as needed to save on a miniscule amount of memory pleases me greatly. I realize you can't do dynamic things like that with enums, but I can always just define "actor1, actor2, actor3" etc, and have them function as whatever as needed. The idea is, I can simply call a script that says "set this actor's ID to this instance's ID" and then have another that goes "make this actor have this script" and then somewhere in the obj_actor have it go through and say "if actor is active and actor has a script to run and there is a valid instance ID to access, run the script inside the instance whose ID is stored in the actor." I realize that seems rather complex just to do cutscenes with, but it works in my head.
So my questions are, (A) is this a good way to handle this, or is there a better way that I'm missing, and (B) as the title states, is there anything that I have left out that would make this better/more flexible/easier? I think this seems ok, but who knows.
So I'm working on a top down game. More specifically, I'm working on a cutscene system for a top down game. Recently, I discovered one of the worst ways to handle top down game cutscenes is to run code in a with() statement that just performs an action in the instance that needs to animate for the cutscene. The problems with this are (A) you can't be sure of whether an instance of the object exists- this can be alleviated by calling instance_exists() or whatever that function is, but that's rather cumbersome, and (B) there might be more than one instance of an object in a room, meaning the code would be run in every instance, which could be desirable in some circumstances, but most of the time not.
The system I have worked out in my brain to set up to alleviate this would have a persistent object called obj_actor or something like that which contains a DS map. The map would have a height of three, zero being ID of the instance in the grid, one being whether the instance is currently active or not, and two being the ID of the script being run inside of the instance. Each x coordinate would represent one actor. I would set up an enum of values to correspond with this system of x coordinates. Since, to my knowledge, there is no real way to access the length of an enum in GMS2 (correct me if I'm wrong), I would just put a variable in the enum called "len" or something as the very last variable in the enum and pass it in for the width when creating the grid so that every actor defined in the enum has a spot. I thought about using a map with a string for different actors and the id as a value, but the more I mulled that over in my head, the more complicated it got, and I decided using an enum would just be easier, even though the idea of creating actors and deleting them as needed to save on a miniscule amount of memory pleases me greatly. I realize you can't do dynamic things like that with enums, but I can always just define "actor1, actor2, actor3" etc, and have them function as whatever as needed. The idea is, I can simply call a script that says "set this actor's ID to this instance's ID" and then have another that goes "make this actor have this script" and then somewhere in the obj_actor have it go through and say "if actor is active and actor has a script to run and there is a valid instance ID to access, run the script inside the instance whose ID is stored in the actor." I realize that seems rather complex just to do cutscenes with, but it works in my head.
So my questions are, (A) is this a good way to handle this, or is there a better way that I'm missing, and (B) as the title states, is there anything that I have left out that would make this better/more flexible/easier? I think this seems ok, but who knows.