How would you go about making an inventory with this software? I’m completely new to it. I come from Construct 2 and its similar but different. In Construct 2 I’d add an Array object and set it up for an inventory. Setting up an array on this software seems impossible, and complicated. At least in the same way I’m used to. I also noticed theres no topic or examples about this. Why is that? This software is open source. I’m surprised no one has implemented a feature that would make this easier O.O
You can use structure variables like so:
inventory.weapon.rifle = 1
inventory.ammo.rifle = 10
So you have 1 rifle and 10 rifle ammo in inventory.
To add actual items to inventory UI ,you can use sprite objects as slots having an object variable for each to check if the slot object is used or not and you can create actual items (sprite objects) in positon of each available slot objects like so:
repeat “inventory.ammo.rifle” times
for each object “slot”
if variable “used” =0 of slot, create object ammo at position of slot and do =1 to variable “used” of slot.
This way you create as many items in inventory as many you have in the structure variable.
Once an item is used from inventory just do =0 to variable “used” of slot so the slot can be used again.
After every item have been created in the UI, set the structure variable to 0 as from now on, your inventory UI store the actual items and when you pick up more item, you can simply add +1 to structure variable and run the same event again to add as many item to available slots, as you picked up.
To hide inventory, I recommend to put it on a separated layer and hide the layer and make sure the player can interact with the inventory only when the inventory layer is visible.
This is very basic, and not very practical as every single item take an empty slot, but it works.
Maybe someone else know a better way to do it.
My only problem is I didn’t get any of what you were saying. Im a complete noop. I dunno how to set up the structure variable…or call them or anything. Any way to simplify that? Not trying to sound ungratefull. I apreciate the help. I’m just a complete noob
It not difficult really.
You need to store somewhere how many items you have, to do so you need variables.
Structure variables are basically normal variables but you can use structures separated by a dot:
And you can assign values to different structures within same variable
inventory.rifle = 1
inventory.rifle.ammo = 10
both value 1 and 10 is assigned to same variable “inventory” but in different structure.
You can use such variables to store inventory values.
How many health pack player has, how man weapons, what type of weapons, how many ammo for which weapon…etc
You don’t need to use structures if you don’t want to, but it more practical for this purpose as you can also check if a structure is present or not and you can also remove and add structures later. But if you find it too complicated you can use normal variables don’t be confused. Variables needed to store how many items you actually have, simple as that.
And my suggestion for the inventory basically is to use variables to create inventory items in the graphical user interface (GUI) of the inventory.
The graphical user interface of inventory should have slots and items in the slots right? I suggest to use sprite objects as “slots” and “items” in the GUI.
For example let say you have 10 rifle ammo in your inventory variable so you want to have 10 rifle ammo inside the GUI as well but you want to make sure 10 ammo takes only 10 slots inside the GUI of the inventory.
In GD you have special events such as “repeat”. You can use this event to repeat an event specified number of times. In this case you want to repeat as many times as many ammo you have in your inventory so when you select the repeat event from the list you need to enter Variable(inventory.ammo.rifle) as expression to
repeat “inventory.rifle.ammo” times the event
But you need to make sure only one item can be created in position of a slot.
In GD every object can have it own object variable to store values individually for different instances of same objects, so basically you can use the same sprite object for each slot, if you want 20 slots, you don’t need 20 different objects, you can use only 1 object 20 times but you need an object variable individually for each copy.
Such object variable can be used to check if a slot is used or not, empty or not.
For example you can have a variable “used” for each slot object with value 0 which means they are empty, available.
Now, using structure variables or any variable you can create actual objects in position of slot objects.
At this point you just need to check value of object variable and create an object in position of slot if the value of object variable of slot is 0, but you need to make sure once an item is created in the position of a slot, the object variable of the slot become 1 or anything but not 0 as it used so no other items can be created in the same slot.
So the solution is:
repeat "inventory.rifle.ammo" times
---if variable "used" =0 of slot, create object ammo at position of slot and do =1 to variable "used" of slot.
When an item is used do =0 to variable “used” of slot so it become available again…
I hope it helps, but really if you have no experience with GD you should try simple things first. Maybe you are an advanced user of C2 but GD is different, yes it also using events and expressions similar to C2 but this is where the similarity ends.
First of all I appreciate this very much. Imma try and figure things out a bit. I’m working on a Framing game. Similar to Harvest Moon. So Imma have to adapt it a little diff. Do I have to have a repeat event for all the items object, or could I store all the Items (Tool, Items, Seeds) in one object and just call the frame, or animation like in construct 2? I wish someone had make a full inventory example with pics and everything. That would have been nice. I dunno how long GDevelop has been around. But there aren’t many examples so far of some of these. (What I might consider) Basic questions. At least I haven’t found anything yet. Only found One video too, and it was for something completely different. Once again appreciate your help. I should have been a little more specific about the type of game I was making.
Yes and no.
You can use only one object having different animations. When you create the item in the inventory, just change it animation for example like this:
repeat "inventory.rifle.ammo" times
---if variable "used" =0 of slot, create object at position of slot and do "ammo" to animation of object and do =1 to variable "used" of slot.
But you need to repeat this for every type of item as you store actual number of items in different variables or structures for each type.
repeat "Variable(item types)" times
Please note in GD you can’t use custom names for animations, every animation has it own number such as Animation 0, Animation 1, Animation 2…etc and you need to use it number. So if the ammo animation of the object is Animation 1, you need to use “do=1 to animation of object”.
But as I have mentioned it not a good example, maybe someone else know a better way to do an inventory.
Any way of having it do it by frame rather than animation tho? Thanks btw
Edit: Also do I set the structure variables as global, or scene variables?
Yes, you can do it by frame. Just set the frame of the object when you create it.
Note that, GD doesn’t support sprite sheet, so every frame need to be a separated image, GD has a built in tool to decompose a sprite sheet, you can find it under “Projects” tab and “Image converter”.
Object variables stay in memory as long an object is present in the scene, once an object is deleted, it variables and structures deleted from the memory is well.
Scene variables stay in memory as long the scene is running, if you change scene, it delete the scene variables and it structures from the memory.
Global variables stay in memory as long the game is running, it delete from memory only when you quit the game.
Convinient to use global variables but you also need to consider memory usage of the game.
If you going to use structures, it doesn’t really matter as you can delete structures when they don’t needed any more, this way you can keep the memory usage at minimum by having only 1 variable, object, scene, global no matter as long you delete structures when don’t needed.
If you do it as I suggested, after items created in the GUI, the actual structure don’t needed any more as the objects are stored in GUI so you can delete the structures of the variable and free up memory this way.
So, at the beginning of the game, when it started for the first time, if you wan’t some items in the inventory just create the variable, structures add the values and create the tiems in the GUI from variables, and delete the structures. Or just simply add the item to the GUI in the editor.
When the player pickup an item:
First check what kind of item is that. If it ammo for example, create a structure “ammo” for variable “inventory”.
Second, check the quantity of item picked up and add the value to structure “inventory.ammo = 1”.
Third, check the existence of structures, if a structure is exist create objects in GUI using the value of the structure and finally, delete the structure.
This way you can keep the memory usage of your game at minimum level by having only 1 varibale (no structures, only one variable) in the memory all the time for inventory items. To keep inventory when you change scene, you can save the inventory in to an external file, and load inventory from file at the beginning of a new scene. You goin to need such save-load function anyway in your game if you want the player to be able to save the game and load it later.
GDevelop has an example called “basic level editor” which has a basic save and load function so you can check that how to save something in to a file and load it.