- Edited
I wanted to move from my json data base to resources in order to keep track of metadata like status, durability, exp, etc. So I created to do the job for me. The resources are created and I can open then in the inspector all the variables have their values properly set, but when I click on another resource and go back to the first inspected resource all of a sudden all the variables of the type int except 1 durability get reseted?!
This is the Script for the Item resource:
extends Resource
class_name Item
enum SEASONS {SPRING,SUMMER,AUTUMN,WINTER}
export (String) var name
export (String) var animation
export (int) var frame
export (int) var max_stack
export (int) var sell_price
export (int) var buy_price
export (String) var category
export (Array) var seasons
export (Array) var recipes
export (int) var amount
export (int) var experience
export (int) var durability
And this is the script to create the resources.
func create_resources():
var items_data = DBase.Items
for key in items_data:
var new_resource = Item.new()
new_resource.name = key
new_resource.sell_price = items_data[key][DBase.SELL_PRICE]
new_resource.buy_price = items_data[key][DBase.BUY_PRICE]
new_resource.max_stack = items_data[key][DBase.MAX_STACK]
new_resource.animation = items_data[key][DBase.ANIMATION]
new_resource.frame = items_data[key][DBase.FRAME]
new_resource.category = items_data[key][DBase.CATEGORY]
if items_data[key][DBase.RECIPES] != null:
new_resource.recipes = items_data[key][DBase.RECIPES]
else:
new_resource.recipes = []
if items_data[key][DBase.SEASON] != null:
new_resource.seasons = items_data[key][DBase.SEASON]
else:
new_resource.seasons = []
new_resource.amount = 20
new_resource.experience = 10
new_resource.durability = 100
ResourceSaver.save(str("res://ZZ_Resources/new_resources/"+key+".tres"),new_resource)
If I press on the resource once and with the values properly set I click on save resource on the inspector it gets the same variables set to 0
The variables set to 0 are all integers:
export (int) var frame
export (int) var max_stack
export (int) var sell_price
export (int) var buy_price
But there's some integers that don't get reseted among other variables:
export (String) var name
export (String) var animation
export (String) var category
export (Array) var seasons
export (Array) var recipes
export (int) var amount
export (int) var experience
export (int) var durability
I would also like to point out that there seem to be some kind of problem when setting the variables because I used to have:
export (SEASONS) var seasons
and this didn't pop an error when trying to set its value to []
when it should right ?