Quote:
Originally Posted by xAndrewx
I would really recommend a new system, you could do something like
HTML Code:
public function onCheckArray(arr) {
for (temp.i: getstringkeys("this.")) {
if ((@ this.(@ temp.i)) == (@ temp.arr)) return true;
if (temp.arr.size() == this.(@ temp.i).size()) {
temp.check = 0;
for (temp.f: temp.arr) {
if (temp.f in this.(@ temp.i)) temp.check++;
}
if (temp.check == temp.arr.size()) return true;
}
}
return false;
}
|
That would require relying on a "hack" function retrieving like that could become problematic.
1. Store each recipe id in an array. (this.recipes = {})
2. Store recipe information in it's own variable. (this.recipe.(@id) = {"name", {"ingredient", 1, "other", 1}})
3. Cycle through each recipe and provided ingredients until a match is found.
Rough implementation:
PHP Code:
function getResult(ingredients) {
temp.found = "";
for (temp.recipe: this.recipes) {
temp.requires = getRequirements(temp.recipe);
for (temp.i = 0; temp.i < ingredients.size() && ; temp.i += 2) {
temp.item = ingredients[temp.i];
temp.qty = ingredients[temp.i+1];
// Matching requirements
temp.ind = temp.requires.index(temp.item);
if (temp.item in temp.requires && temp.qty >= temp.requires[temp.ind+1]) {
// Matching ingredient
}
}
if (temp.found) break;
}
return temp.found;
}
function getResult(recipeid) {
return this.recipe.(@recipeid)[0];
}
funciton getRequirements(recipeid) {
return this.recipe.(@recipeid)[1];
}