How do I format my confusing dictionary? Or, do I use a class instead?

Godot_v4.1.1

This is my first game, so I thought I’d make a short and simple baking simulation game. How I want it to work is that your main goal is to create a dessert that matches one of the randomly generated tags of the day. For simplicity reasons I’ll only list 3 tags; spicy, sweet, and sour. Making your dessert involves two steps: mixing the ingredients and then adding toppings, with both categories of items having various levels of spiciness, sweetness, and sourness.

So lets say you need to use the sour tag. You add (ingredient) lemon to the mixture, which has 5 sourness points. Then when you go to decorating you add (topping) limecustard which adds another 5 points. You need 10 points over all to be able to use the sour tags, so now you’ve met your goal.

It seemed super simple in my head, but now that I’m trying to write down just the dictionary I am struggling (probably because it’s my first time, so no worries I know I’ll figure it out if I give myself some patience). I was thinking of using a nested dictionary like this

var Item = Dictionary : { “Ingredient” : { “lemon”, “sugar”, “cinnamon” }, “topping” : { “limecustard”, “strawberry_icing”, “somethingspicy” } }

But then I realized that I don’t know how to give the individual toppings and ingredients the sour variable. So then I thought of ditching the item dictionary maybe using classes?

class_name Item
var name
var desc
var sweetpoints
var sourpoints
var spicypoints

var Ingredient1 = Item.new
Ingredient1.name = “Lemon”
Ingredient1.desc = “A roundish, yellow, and sour fruit”
Ingredient1.sweetpoints = 0
Ingredient1.sourpoints = 5
Ingredient1.spicypoints = 0

var Topping1 = Item.new
Topping1.name = “Lemon”
Topping1.desc = “A roundish, yellow, and sour fruit”
Topping1.sweetpoints = 0
Topping1.sourpoints = 5
Topping1.spicypoints = 0

And then I think I would try to make a class that’s like, the whole dessert and the Topping sourpoints would be combined with the Ingredient sourpoints for the total sourpoints (dessert.sourpoints maybe)?

But I was also told by some different tutorials online that I would need a dictionary in there somewhere. Can I make dictionaries interact with classes somehow? As in, create a variable in a dictionary and then use that in a class later? Or would using classes here at all not work out?

Thanks for anyone willing to help! I’ve been trying to do this on my own until now!

You could create ingredients and recipes as Resource.
This way you can rickclick in filesystem → new resource → ingredient
Exporting the variables allows then filling in their values from the inspector (You need to define their type when using @export)

class_name Ingredient extends Resource

@export var name : String
@export var desc : String
@export var icon : Sprite2D
@export var sweetpoints : int
@export var sourpoints : int
@export var spicypoints : int

The same can be done with recipes:

class_name Recipe extends Resource

@export var recipe_name : String
@export var desc : String
@export var ingredients : Array[Ingredient]

Simply create new recipes, doubleclick them and then in the inspector you can add more ingredients to the array. Using quickload also shows you all ingredients you already have created.

1 Like

Oh my god, this looks like it makes things so much easier! I swear I’ve been researching how to do this for months and I thought I was stuck at a dead end.

I’ll try this out & I’ll let you know if I have any questions that I can’t find answers to

Thank you!

1 Like

Ignore the Sprite in the Ingredient. It should be Texture2D. :upside_down_face: