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

Does anyone know how to make a Zelda-Invetory

M

Meowmere

Guest
I want to make one that can store different items as apposed to Zelda where theres only 1 of each object, I want to make it have a discard button, so far I have a room inventory that has a selector that moves to each tile and the selector whenever you press Z X or C it creates a sensor object for each of those keys.

Like this http://imgur.com/a/RLid3
I'd also like help on making the crafting possible, but that seems to be alot easier than the inventory itself.
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
I'd use a (global) 2D array to store the items in each inventory cell, and then create the right objects when you switch to the inventory room. You'd need a "nothing" value, but you could use the built-in noone for that. Fill the inventory with that value, and then each time you pick up an item, go through all cells of the array until you find an empty cell, then put the index of that object there.
 
M

Meowmere

Guest
thanks, that *may* work, if it doesn't I'd still be very VERY, happy if people kept providing help.
 

Yal

🐧 *penguin noises*
GMC Elder
By the way, if you keep updating us on what you're doing and/or what you've tried (in as much details as possible), it'll be easier to suggest relevant things for how to proceed.
 
Z

Zekka

Guest
YAL's representation is good. I've used versions of it before and was pleased with the results.

A 1-dimensional array is also an option, though. For a 3x8 grid, you say that indices 0-7 are the first row, 8-15 are the second, and 16-23 are the third. You only think of it as '2D' when you draw the inventory screen. (or create the objects for it, etc.)

Representing it this way may make it easier to write a loop that does something for every index in your array, and it means you can describe each slot with just one number instead of two. (e.g, instead of writing second row, first column as the pair (1, 0), you can write it as just the index `8`) This means you only have to use one variable to e.g. store which slot the user has placed an item in.

Let me know if you need any example code for this. I don't know if I'll be around but someone else might if I'm not.
 

Yal

🐧 *penguin noises*
GMC Elder
For a 1-dimensional array, you can use the div and mod operators to get the x and y coordinate like this:
Code:
xp = index mod stuff_per_row;
yp = index div stuff_per_row;
 
Z

Zekka

Guest
Likewise, getting the 1D index from the 2D coordinates is like this:

Code:
var ix = yp * stuff_per_row + xp;
(Of course, this code doesn't check if xp is between 0 and stuff_per_row, or if yp is between 0 and the number of rows.)
 
P

Paolo Mazzon

Guest
Personally, I generally think that using dynamic memory such as maps and lists is a much better idea. I would not use a 2D array/grid; since it makes accessing/iterating a bit more of a pain.
 
Z

Zekka

Guest
IIRC maps and lists don't play that well with the savegame system yet, but if that's not a problem for you then you probably don't have anything to worry about. (There are workarounds for this but I don't know them.)
 

Yal

🐧 *penguin noises*
GMC Elder
Both global and local arrays (1D and 2D) get saved and loaded with the built-in save system, I can attest to that. (I originally had that for Gun Princess Zero's save system to save jam time, but it led to issues when I tried updating the map data - which was saved in global arrays - and it would load it from the savefile instead of using the newly generated, so I ended up having to code custom saving and loading to save test playing time...)
 
P

Paolo Mazzon

Guest
I can't say I have ever had a problem saving/loading data structures. For this situation, assuming you're using a list and not a grid, you could really just have an INI file with a section for each index; assuming each index is a map. Then in a header named "general" or something put the length of the list. You could also just save it as a text file, going by line offset for each index. For example, let's say you have 3 things in each map (in each index of the list) called name value and desc. You could store it like
Code:
<name>
<val>
<desc>
<name>
<val>
<desc>
...
And you would know that every 3rd line is a new entry.
 
Z

Zekka

Guest
It's not literally automatic under GM's save system though, as far as I know. For some people I bet that makes a big difference, even if it doesn't necessarily make a big difference for you.
 

dannerz

Member
I want to make one that can store different items as apposed to Zelda where theres only 1 of each object, I want to make it have a discard button, so far I have a room inventory that has a selector that moves to each tile and the selector whenever you press Z X or C it creates a sensor object for each of those keys.
I've done it before.

It's hard for me to describe. Looking for a "free slot" in the list. I use the repeat function.
It moves the object to check if there is another object there already. If it is a free space,
the object stays in that location. Each object has its own sprite an variables such as
stacking an amount of numbers on that single object. An advanced game would require
a large number of variables for each of the objects. Like speed, jump height max,
health, strength, experience, defense, mana, armor level, etc.
 
P

Paolo Mazzon

Guest
It's not literally automatic under GM's save system though, as far as I know. For some people I bet that makes a big difference, even if it doesn't necessarily make a big difference for you.
?

Of course it's not built in. There is no "built-in" save system for Zelda-style inventory systems, you will have to write your own, no matter what method of inventory management you use.
 
Z

Zekka

Guest
There's game_save(), which saves the complete state of the game, which is what a lot of folks use when they don't want to go to the trouble to write their own save system.

(Unless GM:S took that out? I seem to remember it being there, but I haven't seriously used it since GM7.)
 
P

Paolo Mazzon

Guest
There's game_save(), which saves the complete state of the game, which is what a lot of folks use when they don't want to go to the trouble to write their own save system.

(Unless GM:S took that out? I seem to remember it being there, but I haven't seriously used it since GM7.)
I think it goes without saying that game_save should be used for nothing but debug purposes, and as it states in the documentation
more advanced users may prefer to code their own system using the File functions, due to the fact that the game will not save any of the dynamic resources like data structures, surfaces, added backgrounds and sprites etc..
Basically speaking, every new build of your project's save file in incompatible with the last, whereas a proper save system would (generally) not be; and even if it did, it wouldn't save any data structures, should Meowmere choose to use any.
 
Z

Zekka

Guest
It sounds like we've kinda covered the tradeoffs for game_save(). I think you're correct that most of the time it isn't what you want to use, for reasons like this, but you've also got to consider that what's easy for you often isn't easy for other people, particularly people who are new.

When you make a suggestion to a broad audience, I've usually found it's kind of important to make sure that you can reach as much of that audience as possible, so I think it's important to consider implementation options that are friendly even to bad design. (or at least what you think is bad design)
 
M

Moon Goat

Guest
You could store the items as arrays in a data structure, so you can assign multiple variables to each item, like so:

var item;
item[0] = obj_sword; //The Object
item[1] = 12; // Stack
item[2] = ord("H"); //The
discard key, in this case, H.

//Adding to Inventory
ds_list_add(inventory, item);

//Reading Inventory
var check_item = ds_list_find_value(inventory, 0);
current_weapon = check_item[0]; //Set current weapon to object index of this item
 
M

Meowmere

Guest
Moon goat, would there be any way to add descriptions to the items?

Also... I use my own saving system, it just saves every savable value and the room in a txt file. Cheater's can go crazy for all I care.
 
Last edited by a moderator:
M

Meowmere

Guest
I'm also not sure how to implement Moon Goat's, theres around a grand total of 100 items-ish, some are swords, would there be a way to add dmg? The player has a global damage amount in the stats object.
1 more thing, the inventory is in spaces of 32x32, so every 32 pixels theres a slot.
 
Z

Zekka

Guest
With Moongoat's solution you can probably just use column 3 as a description, 4 as damage, and so on. Right now he only has dedicated uses for columns 0, 1, and 2, so you can put anything you want in other columns.

You could make ITEM_DESCRIPTION, ITEM_DAMAGE global constants equal to 3 or 4, so instead of looking at arr[3], you can look at arr[ITEM_DESCRIPTION], which is easier to read and not get confused by.
 
M

Moon Goat

Guest
My idea is that you could use actual objects for the items in your game, and then assign variables to them to access:

obj_sword : damage = 3;

current_weapon = obj_sword;

ememy.hp -= current_weapon.damage;

The inventory item arrays would be just for storing dynamic changable variables, such as stack amount and recharge time.
 
Last edited by a moderator:
M

Moon Goat

Guest
Also for the save system, you could actually save the data structure inventory with ds_list_write and write the string into a text file, which would be unreadable to human eyes.

Hope this helps!
 
M

Meowmere

Guest
would someone like to use the source code to help me? I'm so close to finishing, I just need 2 things, pushing and an inventory because this is really complex for me, also if you want the source code to help me out, PM me.
 
P

Puhloo

Guest
You can create a database of the items with their own information through a script like inventory_database_get(item id, item information); or something and then setup a switch statement that returns what information you'd like to get. Then create a ds_grid or a 2d array for the inventory space.

EDIT: I'll make a gmz file for you to look at how I do inventory and stuff. I'll PM you afterwards.
 
P

Paolo Mazzon

Guest
My idea is that you could use actual objects for the items in your game, and then assign variables to them to access
I don't think I agree with this method. There is a lot of inherit overhead with creating objects; and since they are purely for memory you end up wasting a lot a CPU cycles processing something that doesn't need to be processed every frame (Especially if you plan on using instance_activate_* and instance_deactivate*)
 
M

Moon Goat

Guest
Objects themselves don't take up CPU power, but instances of objects that are active do. Also, I was thinking that the player could pick up an object which would store it's index and other variables as an array in the player's inventory. The stored items wouldn't be active objects.
 
L

Lotias

Guest
Objects themselves don't take up CPU power, but instances of objects that are active do. Also, I was thinking that the player could pick up an object which would store it's index and other variables as an array in the player's inventory. The stored items wouldn't be active objects.
You need an instance active to access any of those variables. Just use data structures - this is a needless workaround.
 
P

Paolo Mazzon

Guest
Objects themselves don't take up CPU power, but instances of objects that are active do. Also, I was thinking that the player could pick up an object which would store it's index and other variables as an array in the player's inventory. The stored items wouldn't be active objects.
Taken from the documentation
It is normally not necessary to deactivate instances every step of your game and this can actually cause your game to lag and runs slow
Disregarding all CPU overhead of just having the object exist, deactivating and activating objects in itself is CPU intensive. You're using more CPU than needed and more ram (Since even empty objects all have built in methods/variables) for something that could just as easily (arguably more) be achieved with multiple arrays or data structures.
 
M

Moon Goat

Guest
You need an instance active to access any of those variables. Just use data structures - this is a needless workaround.
Actually you don't. You can access an object's variable as well as individual instances of that object.
 
L

Lotias

Guest
Actually you don't. You can access an object's variable as well as individual instances of that object.
Haha, what? If no individual instance of that object exists you'll get an error immediately.
 
Z

Zekka

Guest
If your game lags, it probably won't be because you created twenty or thirty extra objects to represent the inventory.

Even in the old, extremely slow versions of Game Maker I could get 700 objects in a room with actual code in their Step and Draw events and only see minor performance degradation.
 
P

Paolo Mazzon

Guest
If your game lags, it probably won't be because you created twenty or thirty extra objects to represent the inventory.

Even in the old, extremely slow versions of Game Maker I could get 700 objects in a room with actual code in their Step and Draw events and only see minor performance degradation.
You're using more CPU than needed and more ram (Since even empty objects all have built in methods/variables) for something that could just as easily (arguably more) be achieved with multiple arrays or data structures.
it's inefficient
 
Z

Zekka

Guest
You're probably already making inefficient use of resources because you chose to use GameMaker.

Before you make performance advice, could you verify that the questioner is actually experiencing a performance problem? I feel like a real jerk saying this, but I feel like your priorities are pretty different from the priorities of the asker. (who has not brought up efficiency) When you tell someone "you shouldn't do X because of Y" but Y isn't something they care about, they usually won't listen to you.

I used to have a really bad habit of making suggestions people didn't have a use for, and mostly they ignored me when I did this.
 
ok first off do you know how to create, load and save information from a data.dat file inside of gms?

if you do then this is a trivial thing to do, just assign a variable to represent the number of said item in your inventory and each time one is gained or consumed save it to the data.dat file, that way even if the game crashes you will still have the full list right there.

my suggestion is go into the story and buy easyiapeasy, has a full system for making and using iap purchases which is very nice but the layout makes it very easy to save things other than game tokens, all you have to do is pick what you want in the inventory and when you do specific events to change the number of objects in the inventory then use the same system in easyiap easy thats use to record the consumption or increase in purchases from the store *just without the store call event.

good luck.
 
Z

Zekka

Guest
ok first off do you know how to create, load and save information from a data.dat file inside of gms?

if you do then this is a trivial thing to do, just assign a variable to represent the number of said item in your inventory and each time one is gained or consumed save it to the data.dat file, that way even if the game crashes you will still have the full list right there.
For what it's worth, opening and closing files in response to user action probably actually will create a noticeable performance problem if you do it very often. If you only do it when the player makes a UI action that affects the inventory, they probably won't notice, though, so this might still be OK. (IIRC, Hotline Miami frequently opened and closed files between deaths and most players didn't notice.)

I think a paid extension might be mild overkill for this use case, but I haven't used easyiapeasy and it's possibly way better for this than I'm guessing it is.
 
For what it's worth, opening and closing files in response to user action probably actually will create a noticeable performance problem if you do it very often. If you only do it when the player makes a UI action that affects the inventory, they probably won't notice, though, so this might still be OK. (IIRC, Hotline Miami frequently opened and closed files between deaths and most players didn't notice.)

I think a paid extension might be mild overkill for this use case, but I haven't used easyiapeasy and it's possibly way better for this than I'm guessing it is.
yeah i understand what you mean about it being a bit overkill its just that in solving this one problem he would end up with a solution to that and a whole bunch of other stuff which could be really useful in the future.

the question of lag is of merit but you are only loading information from the data file when the game starts where you pull the information and store it into a series of variables in game, the rest of the time all you are doing is saving to the file as those variables change, allot less pressure on the system putting stuff into the data.dat file than taking it out.
 
ini is great and its a good way to learn but it is not at all secure, people can cheat by opening up a single file and tinkering with numbers

you should move over to data structures as soon as you can for the simple fact that they have to crack open the entire system (and thus invalidate the entire yyc compiler module used) in order to cheat using them.
 
P

Puhloo

Guest
ini is great and its a good way to learn but it is not at all secure, people can cheat by opening up a single file and tinkering with numbers

you should move over to data structures as soon as you can for the simple fact that they have to crack open the entire system (and thus invalidate the entire yyc compiler module used) in order to cheat using them.
You do know that you can save a data structure inside an ini file or a text file, right? Saving ds_map to a file: ds_map_write(id);
 
no i did not, thank you for teaching me something new. :)

but i still say that if he is going to put an inventory in a game he should take steps to make sure people wont exploit it for unlimited arrows or something.
 
M

Meowmere

Guest
I may just put the source code up here, if anyone asks for it, ill just plop it on here.
 
L

Lotias

Guest
no i did not, thank you for teaching me something new. :)

but i still say that if he is going to put an inventory in a game he should take steps to make sure people wont exploit it for unlimited arrows or something.
no i did not, thank you for teaching me something new. :)

but i still say that if he is going to put an inventory in a game he should take steps to make sure people wont exploit it for unlimited arrows or something.
Unless it's online multiplayer, there's no reason to try so hard to prevent save edits. If players want to cheat they'll find a way, regardless of how complex your save protection system is. It's wasted effort on that front. Even with the ds_blank_write functions, players could translate the resulting string from hexidecimal and back.

There's a whole argument out there where people complain that cheaters ruin the experience for themselves, when it's just that - they're ruining it for themselves. There's not much reason to care about it outside of competitive or MMO games.
 
M

Moon Goat

Guest
By the way the art in your game looks amazing! Did you do it all yourself, and if so, would you be willing to share some knowledge on how to pick colors and animate?
 
Top