Search code examples
c++eventsgame-makergml

Is it possible to create a dynamic room by passing in variables?


I am attempting to create a framework where I can have multiple events all use the same room.

For example, the player triggers an event and the event builds the room with the passed in variables.

I am having trouble making the room dynamic. I want the room and the objects in the room be reusable for every event. This includes the buttons as well.

  • Is this possible to do?; OR
  • Do I have to create separate rooms for each unique event I wish to create?

The game is mostly menu based (like the game "Long Live The Queen") if that helps.


Solution

  • To answer simply, yes it is possible.

    There are a lot of cases where I have been able to fit a lot of stuff into a single room in Game Maker. Here are a few ways to achieve this "dynamic" game creation:

    • Files and Scripts. You can use a single room to hold a variable number of levels by storing walls, floors, player positions, events, etc inside of a file. You can make a script that takes the filename (your "passed in" variable) and then let it simply create all of the instances inside the level for you in that room. You can also have a function that cleans up the room to prepare for another level to load. The side effect though is that your uniqueness is limited to what information can be stored in those files. You can store menu options and text dialog too if you wish.
    • "Unique" Objects. Game Maker is an IDE. There is nothing stopping you from making new objects in the editor for a unique case and then adding a handler in another object to create it on demand. You have to manage switching between them though.
    • Make a "manager" object. It can handle all of the events of something happening in-game (and in that room, for that matter). Plus also it can be used by objects to store non-global variables before being destroyed. For instance, if a character dies, it can set a variable in a manager object to "true", which would trigger a boss to appear.

    In terms of manipulating object events dynamically though, unless you are running something like Game Maker 8, that is no longer possible. I say this because prior to GameMaker:Studio, object, sprites and others can be created dynamically in game via functions like "object_add()". Of course, these are obsolete and can no longer be used. Nevertheless, there are always ways around it.