Dabbling with Drag n Drop Crafting

13
Official Construct Team Post
Laura_D's avatar
Laura_D
  • 7 Aug, 2020
  • 349 words
  • ~1-2 mins
  • 1,407 visits
  • 1 favourites

Happy Friday! I am trying to write this blog while also trying to not melt into a puddle – it's proving challenging, but I shall persevere!

This week I've been messing around with the mini crafting project that Kyatric sent me. I'm happy to say it now functions quite nicely as a little drag-drop crafting system. The project uses a JSON to store the item data and crafting recipes and an array to store the information about which items you're trying to craft with.

When you drop an item on top of another item, the item's IDs are saved to the array and a function is called that begins the check as to whether those two items can make something.

The function runs a couple of validity checks to see if the IDs of the two picked items can create something according to a recipe. If a validity check is passed, the corresponding global boolean will be set to true.

If the two item IDs in the array match the two ideas stored in a recipe, then the new item is generated and the two used to make it are destroyed. Because all of the crafting items are just instances of the same object, we need to add in an extra check to make sure that only the objects used for crafting are destroyed. A Boolean variable on the items object solves this.

Two global variables store the value of the item ID for the item that is picked up and the one it's dropped onto. When the picked items have been confirmed to be part of a recipe, the global variables are use to set the correct Boolean variables to true. Then when destroying the objects, only those which have the Boolean set to true are actually destroyed. So if you have multiple copies of one type of item, only the one you've used will disappear!

This may become a tutorial, but the file needs a fair bit of tidying/commenting before it's a tutorial-level example. Depends how useful people think it is!

Enjoy your weekend!

Subscribe

Get emailed when there are new posts!

  • 6 Comments

  • Order by
Want to leave a comment? Login or Register an account!
    • [-] [+]
    • 2
    • 2 points
    • (1 child)
    [deleted]
      • [-] [+]
      • 1
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 1 points
      • (0 children)

      Glad you're enjoying the blog posts! Work on the actual game has slowed somewhat while I build out these smaller projects to test the mechanics. So there will come a time soon where I have to shove them all together and hope they work!

      JSON is relatively new to me, but it's proving to be a really useful way to store data. So far it's being used in the dialogue and inventory systems, and I like how it fits into crafting so it'll probably end up in the final version of this system too!

  • Fiz jogo Puzzle no Construct 2 entrei no 3 😔☹️😔 e abri o jogo 2 vez. Agora quero abrir o jogo não consigo.

    Mensagem que o Canvas não está instalado..

    Posso vender o jogo no Construct 2 Gratuito.

    Qual o preço que a Scirra cobra para vender jogo?

    Aguardo resposta.

  • Boa noite Laura_D.

    Tudo bem contigo?

    Espero que sim.

    Elaboro Jogos Educacionais.

    O Uso de arrastar e soltar é muito prático para ensinar crianças a ler. ( Alfabetização). Estou com Construct 3 há 3 semanas. Ainda Estou aprendendo. Estou elaborando um jogo com palavras. Usei o Sistema te Puzzle, onde as peças são as palavras. Um sensor para posição das palavras.Mas não sei como fazer para correção se estão certas ou erradas. Voce pode me dar uma dica? Tipo: Uma imagem de um livro, arrasta a palavra livro ao encontro da imagem, e se o jogador arrastar outra palavra tipo: lápis; estará errada como fazer?

    Desde já agradeço sua atenção.

    Se cuida. Deus abençoe voce e sua família. Amém

  • This is awesome! I'm currently working on a cooking with over 40 events to match 6 different recipes. Hopefully this will help others who are looking to make games in this genre.

      • [-] [+]
      • 2
      • Laura_D's avatar
      • Laura_D
      • Construct Team Community Manager
      • 2 points
      • (0 children)

      I can definitely recommend JSON as a way of storing recipe data - helps keeps your events down too! Good luck with your project!