Creating ds grids in game

M

Michael Horsley

Guest
I am making a game that involves using chests. I am going to use a ds grid for the chest's contents but I am running into a problem. I don't want to use the same ds grid whenever I create a new chest in game, I want each chest to have its own ds grid that I can save to an ini file. How would I go about doing this? :)
 
B

bojack29

Guest
You use a grid for the contents of the chest? Why? The chest has multiple items in it?
 
M

Michael Horsley

Guest
You use a grid for the contents of the chest? Why? The chest has multiple items in it?
Yes, unless there is a better way to do it that will work similar to minecraft or other games with grid based inventory.
 
W

whale_cancer

Guest
Yes, unless there is a better way to do it that will work similar to minecraft or other games with grid based inventory.
Are your chests instances of the same object? If so, you need to choose a method for randomizing contents (or, if you are placing them in rooms manually, you can edit their start code for each instance to place items into the ds_grid manually). A simple way to randomize would be to generate a random number from 1 to 20, for instance, and have a switch statement that places contents into each chest on creation using the random number you generated.
 
M

Michael Horsley

Guest
The chests will be a placeable object in the game, so while they will spawn randomly in the level, you can also create chests yourself and place them wherever you want. (I swear it's not another minecraft clone:p )
 
B

bojack29

Guest
You could create a global list at game shuffle its contents. When a chest is opened the chest simply selects the item at the top of the list and reshuffles without ever taking an item from the list.
 
M

Michael Horsley

Guest
I see what you are saying, but what I am referring to is saving the contents of a chest you place yourself. So it wouldn't be the game randomly spawning a chest, rather you would actually be placing the chest and then at that point you can fill the chest with whatever you want and then have the contents save to a file. So in theory you could create a hundred chests and fill them with all your items, and then save all the contents of each individual chest. I hope I am making sense lol
 
B

bojack29

Guest
So each chest is randomly filled, but the contents stayed after being saved to?
 
W

whale_cancer

Guest
I see what you are saying, but what I am referring to is saving the contents of a chest you place yourself. So it wouldn't be the game randomly spawning a chest, rather you would actually be placing the chest and then at that point you can fill the chest with whatever you want and then have the contents save to a file. So in theory you could create a hundred chests and fill them with all your items, and then save all the contents of each individual chest. I hope I am making sense lol
Then you just have a ds_grid local to the instance that you manipulate. I don't see the issue.
 
P

Puhloo

Guest
You don't actually need to use multiple ds_grids unless you want to open many chests simultaneously.
Whenever you place a chest, add a unique ID to it and save it's data to an .ini file.
Whenever you open a chest, clear the ds_grid and load the data from the data file by using the unique ID to the ds_grid.
Whenever you close a chest, clear the ds_grid and save the data to the data file at its respective unique ID.
 
M

Michael Horsley

Guest
You don't actually need to use multiple ds_grids unless you want to open many chests simultaneously.
Whenever you place a chest, add a unique ID to it and save it's data to an .ini file.
Whenever you open a chest, clear the ds_grid and load the data from the data file by using the unique ID to the ds_grid.
Whenever you close a chest, clear the ds_grid and save the data to the data file at its respective unique ID.
But my problem is finding a way to create a unique ID for each chest without hard coding it in. I need a way to create a new ID for each chest you place.

Edit: Actually that makes sense. I guess I could just use a variable to represent which chest has been placed and then whenever you place a chest it increases the number so that each chest has a unique value, and then put that variable into the key section before saving the grid.
 
Last edited by a moderator:
W

whale_cancer

Guest
But my problem is finding a way to create a unique ID for each chest without hard coding it in. I need a way to create a new ID for each chest you place.
When you create a new chest, either in game or in the room editor, it is assigned it's own unique id. It is stored in a local variable called id. This part is already handled for you.
 
W

whale_cancer

Guest
You don't actually need to use multiple ds_grids unless you want to open many chests simultaneously.
Whenever you place a chest, add a unique ID to it and save it's data to an .ini file.
Whenever you open a chest, clear the ds_grid and load the data from the data file by using the unique ID to the ds_grid.
Whenever you close a chest, clear the ds_grid and save the data to the data file at its respective unique ID.
I don't understand why you would want to do this? You are going to be creating and modifying potentially hundreds of ini files for no benefit. Also, after a certain size, ds_grids turned into strings can't be read from .inis (learned this the hard way, though it is unlikely in the extreme that an inventory would surpass this limit).
 
M

Michael Horsley

Guest
So if I understand you correctly, I would just put the id variable in the key when saving to an ini file?
 
P

Puhloo

Guest
You are going to be creating and modifying potentially hundreds of ini files for no benefit
Why create hundreds of .ini files when you can just use one?

I don't understand why you would want to do this? You are going to be creating and modifying potentially hundreds of ini files for no benefit. Also, after a certain size, ds_grids turned into strings can't be read from .inis (learned this the hard way, though it is unlikely in the extreme that an inventory would surpass this limit).
I haven't heard about a chest so big. But if such thing would happen, you can split the inventory in many parts.
 
P

Puhloo

Guest
So if I understand you correctly, I would just put the id variable in the key when saving to an ini file?
Yes. And if you are using multiple ds_grids for different datas of the items, just try adding some kind of prefix or suffix to differentiate it.
 
M

Michael Horsley

Guest
Yes. And if you are using multiple ds_grids for different datas of the items, just try adding some kind of prefix or suffix to differentiate it.
Okay I think this solved it. Thank you all :)
 
Top