Topic was automatically imported from the old Question2Answer platform.
Asked By
JamesButler
Hello folks!
I am super new to Godot, so excuse my newbie questions.
I have a bunch of weapons. Each weapon has an id, an icon, a name and a price.
What is the best way to represent and populate this data in a script?
My wish would be to have a listing of all items accessible from within my main scene where I can adjust the price a little bit without having to go into the code/a .json file.
What are the best practices for things like this?
Also what are ways to make it a bit scalable? Let’s say I have arms dealers who sell different weapons to different prices and there are different classes of players who get bonuses for different weapons (or something like that).
The typical solution to that is something like Unity’s Scriptable Objects. Here are a couple of videos on how to do that in Godot: https://www.youtube.com/watch?v=wuxal3C0800
The point is to define a new type of Resource. In your example, a Weapon. You define the Weapon’s properties. Then, in the filesystem window, you right click and create a new resource (you should see your new Weapon resource in the list). You then name and save this new resource (ex: Revolver.res) and edit its properties (icon, name, price, sprite, model, etc.) right in the inspector. Your vendor could simply have a path to the weapon resources folder (ex: res://Items/Weapons/) and iterate on the files in that folder to fill its inventory.
Once you’ve defined your resource, you can keep creating new weapons without having to change one line of code.