How to make a cooking system !!!

0 favourites
  • 9 posts
From the Asset Store
Chop the veggies, sprinkle the spices, manage the menu and get your audio production cooking with Cooking Game.
  • I want to make a cooking system. I created a Json and wrote the content. But how can I determine if the food in the scene is the food I need to synthesize?

  • What kind of JSON did you create? Can you post an example of what the json looks like so we can assist?

  • Since you already have a Json content to store the recipe.

    it might be like this:

    {
     "Pancake": { "id": 1, "ingredients": ["flour", "sugar", "milk", "egg"] },
     "Butter Cookies": { "id": 2, "ingredients": ["flour", "butter", "sugar"] },
     "Muffin": { "id": 3, "ingredients": ["flour", "sugar", "milk", "butter", "egg"] },
     "Cake": { "id": 4, "ingredients": ["flour", "sugar", "milk", "butter", "baking powder"] },
     "Cream Frosting": { "id": 5, "ingredients": ["sugar", "butter", "milk"] }
    }
    

    or like this:

    [
     {"id": 1, "name": "Pancake", "ingredients": ["flour", "sugar", "milk", "egg"]},
     {"id": 2, "name": "Butter Cookies", "ingredients": ["flour", "butter", "sugar"]},
     {"id": 3, "name": "Muffin", "ingredients": ["flour", "sugar", "milk", "butter", "egg"]},
     {"id": 4, "name": "Cake", "ingredients": ["flour", "sugar", "milk", "butter", "baking powder"]},
     {"id": 5, "name": "Cream Frosting", "ingredients": ["sugar", "butter", "milk"]}
    ]
    

    Or You can also join them into strings instead of using arrays.

    "ingredients": "flour,sugar,milk,egg"
    

    Then, a core processing step is to sort the materials and the recipes, so that players can add materials in any order and then match them with the recipes.

    "ingredients": ["flour", "sugar", "milk", "egg"]
    
    // sort
    ['egg', 'flour', 'milk', 'sugar'] 
    

    Then prepare a JSON to store the materials added by the player, and finally compare whether the two contents are the same.

  • dropbox.com/scl/fi/d1jwo9n3q3mkhh91tbi4o/Cooking.c3p

    I have made a list. Clicking on the ingredients will also write them into the json content. But I can't sort them. If the first cell is not egg but other two ingredients, I can't synthesize them.

  • I can't sort the two groups.

  • CookingMatchIngredientsJSON

    I changed the structure of the recipe.

    {
    	"Recipe": {
    		"TomatoEggSoup": {
    			"Ingredients": [
    				"Egg",
    				"Tomato",
    				"Water"
    			]
    		}
    	},
    	"Play": {
    		"Ingredients": []
    	}
    }
    

    I use a JavaScript to match it. If a recipe is matched, return the key name. else or returns None. This name will correspond to your animation name.

    const dataInst = runtime.objects.JSON.getFirstInstance();
    const data = dataInst.getJsonDataCopy();
    const recipes = data.Recipe;
    const playIngredients = data.Play.Ingredients.sort().join(",");
    
    let result = "none";
    
    for (const recipeName in recipes) {
     const recipeIngredients = recipes[recipeName].Ingredients.sort().join(",");
     if (playIngredients === recipeIngredients) {
     result = recipeName;
     break;
     }
    }
    
    runtime.setReturnValue(result);
    
  • If I want the ingredients to have quantities. How should I sort?

  • CookingMatchIngredientsJSON-2.c3p

    you are no longer using an array to store ingredient data, there is no need to sort, just compare the Loop name and the amount.

    {
    	"Recipe": {
    		"TomatoEggSoup": {
    			"Ingredients": {
    				"Egg": 2,
    				"Tomato": 2,
    				"Water": 10
    			}
    		}
    	},
    	"Play": {
    		"Ingredients": {
    			"Egg": 2
    		}
    	}
    }
    
    const dataInst = runtime.objects.JSON.getFirstInstance();
    const data = dataInst.getJsonDataCopy();
    const recipes = data.Recipe;
    const playIngredients = data.Play.Ingredients;
    
    let result = "none";
    
    for (const recipeName in recipes) {
     const recipeIngredients = recipes[recipeName].Ingredients;
     if (Object.entries(recipeIngredients).every(([ingredient, amount]) =>
     playIngredients[ingredient] === amount)) {
     result = recipeName;
     break;
     }
    }
    
    runtime.setReturnValue(result);
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks Man!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)