My initial thoughts are store ingredients in an array
Almost, but instead of storing the ingredients in an array, store the 'recipes' in an array. Now you might think - wait, but a recipie has many information, how? - then the answer is:
structs. The recipie itself is a struct with all the information.
Maybe something like this:
GML:
function my_recipe (_name) constructor
{
recipe_name = _name;
ing_count = 0;
}
But we are not done. Maybe each recipe has a different amount of ingredients needed. So we store them dynamically with a trick.
We go somewhere else, maybe the request controller object, create event and use this struct like this:
GML:
all_recipes = array_create(); //(1)
var _recipe = new my_recipe("Buttered Fish"); //(2)
variable_struct_set(_recipe, "ing_0", "Butter"); //(3)
variable_struct_set(_recipe, "ing_1", "Fish"); //(4)
variable_struct_set(_recipe, "ing_count", 2); //(5)
array_push(all_recipes, _recipe); //(6)
//the other recipes
- Creates the array, that holds all recipes
- Uses our struct, we create one and assign a name to it. The struct has now
recipe_name == "Buttered Fisch"
and ing_count == 0
- creates a new struct variable in your struct named ing_0 and assignes "Butter" to it. Notice the name. The 0 is extremly important. No your struct has also
ing_o == "Butter"
- creates a new struct variable in your struct named ing_1 and assigns "Fish" to it. Again, the name is important. ing_ is the same, but the number is incremented by 1 !!!
- ing_count exists, so it doesn't creates it, but it assigns the number to it. The number matches the ingredients you created (here hard coded)
- Push this recipe with a name, an ing_count and two ingredients into the array
Now the magic happens. How can you check your struct later. The recipes might have different ing_counts, so hard coding won't really work. But we can make it dynamic.
GML:
//accessing the struct from somewhere
player_choice = "Wasabi"; //what the player used
var _correct = false; //checker for later
var _recipe = all_recipes[0]; //the current recipe
var _count = _recipe.ing_count; //how many ingredients are there?
for(_i = 0; _i < _count; _i++)
{
var _ing = variable_struct_get(_recipe, "ing_" + string(_i)) //(A)
if(_ing == player_choice) _correct = true;
}
//just a random evaluation
text = (_correct) ? "Yay" : "Buuh, bad chef";
(A) is the magic. Because we builded the string with a specific method and the function needs a string for finding the struct variable, we can use this.
Random recipe should be obvios:
GML:
next_recipe_number = irandom_range(0, array_size(all_recipes) - 1);
is the easiest one.
How you acutally check your player choices against the recipes or if you wanna make the random requester smarter is up to you.
Edit: Out of my head, not tested, but the logic should work.