• 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!

Legacy GM Spawning Objects in room

P

Pseudo

Guest
Hello GM Community...

The humble bundle finally got me to start on a long-time desire of mine; building a game. I've programmed for years, but nothing in the realm of gaming and, obviously then, never in GML/GM:Studio.

My first game I wanted to try and make was a "Sim Tower" like game.. It was one of my favorites growing up... a simple 2D game.

If you're not familiar, the basic concept I'm aiming for is: You start with enough money to build a floor or two. Each floor will have 3-5 tenants (Either a residential, commercial, office, or (in the future) special tenant)

I've made a tiny skeleton of this game, and was able to make a menu and buttons. However, I have not determined the best way to "draw" the tower.

Right now, I'm thinking of players "buying" an entire floor at a time. This floor would look like it's "under construction" until the player picks their tenant slots for the floor.

Right now, it looks like I only need 1 object for floors, which I'll spawn multiple instances of and stack. This leads me to my first question: What functions do I need to look at to make this happen?
I've created a global variable "floors" to keep track of how may exist, but I'm not sure how to 1) Spawn the floor and make it appear in the right X/Y location, and 2) place objects inside of it. (I'm still thinking through if the tenants should be all one object, or one object per type)

I'd love to have some feedback on how to go about designing this -- I know there's no perfect way, and there's assumptions made, but any commentary would help me in my google-fu I'm sure...

So far:
- I did see instance_create, but that seems more for throw-away objects (not objects I want to persist, and eventually save, and may benefit from some form of "naming"
- I do see there's another thread that shows an issue with "stacking" objects, I'm concerned how that might effect my design.

Would love to discuss!

-Pseudo
 
T

TDSrock

Guest
instance_create would work perfectly fine, you'd just need to store the relevant data of each character you want to persist in an persistent data structure.
 
P

Pseudo

Guest
How do you keep track of them in this case? It doesn't look like there's a way to name the instances with instance_create?
 
T

TDSrock

Guest
By giving each object it's unique identifier.
Create one object that handles all of the characters you have. On it's create event it loads what it needs to load, using it's instance_id when creating you can tell it stuff too.

for example:
Code:
newCharacter = instance_create(x,y,obj_character);
newCharacter.name = "greg";
newCharacter.dataStructureIdentifier = 291927301839;
 

TheouAegis

Member
Your floor should be an array or a ds_grid the full size of the room. Set all values in the array/grid to -1 (under construction). Then set an area to 0 (owned). You may want to allow -2 or lower for unavailable floor (for oddball shapes). For every construct you place in the room, set the corresponding cell in the array/grid to that construct's value. So if you chose to assign a value of 2 for all water pumps and the player puts a water pump in cell 128,50 you'd set cell 128,50 to 2. When you are trying to build something, you check if the cell the piece is over is set to 0, or if it upgrades a cell you check if that cell has the right value.
 
P

Pseudo

Guest
Aha! I didn't realize instance_create returned the reference to the instance! (the doc says; "Return: Real", which I did not translate as the instance reference pointer)

Thanks TDSRock!

TheouAegis: Good point on the array/ds_grid, I didn't think about using an array structure to hold the values, but I can imagine that would make "saving" and "loading" games easier when I get to those functions!
 
P

Pseudo

Guest
Wow! you all are awesome!

I didn't realize Yoyo had their own tutorial channel... A LOT better than the videos I've been finding!

Thanks everyone, love the guidance and help, making this daunting task a good bit easier.
 
Top