Vallar's Forum Posts

  • maybe you can post the c3p file if that's not a problem

    My project is a bit big with multiple event sheets and what not. So I extracted the logic in a separate project and tried again. Still not working properly as it changes the first slot ONLY and ignores all of the others.

    Here is a download link:

    https://www.dropbox.com/s/lnwmp66j052ir1j/Dictionary%20Not%20Working.c3p?dl=0

  • Hard to deduct from the text actually, but I would try the following:

    Change the slot to add an instance variable to indicate it is used. for example "occupied". 0 or 1. Initialise them to 0

    within the Dictionary loop,

    pick by evaluate with expression slot.category = dictionary.currentKey (or whatever holds the category)

    In a subevent. Pick 0th instance of slot. So within the first picking, you've got the first one. So you're left with only 1 slot with the correct category.

    Do your stuff with animations

    Set Occupied to 1.

    Thanks for your quick reply. I followed your instructions 1:1 and it didn't work at all. Here are my events:

    https://i.imgur.com/Ker8pqr.png

    The result is that they are all displayed as empty. I checked the dictionary, checked the animations, checked the categories they all match (strings and spelling wise). What am I missing?

  • Here are some answers to your questions :

    1- This function only returns the index of a specific recipe name inside the JSON. It's useful to build the JSON Path to other properties of a given recipe, namely the components and the quantity needed.

    I see. I am trying to replicate chunks of what you did in my project to understand what you've done and wrap my head around it but I am failing quite a bit. So one thing I am doing is the below:

    https://i.imgur.com/MEVWcPs.png

    I am using the same sample JSON file as you. But when I run the layout, I get the DebugText changed to "00" only. So I am not sure what does this do and what am I getting even since the JSON has no 0s.

    2- That's precisely it. The "stop loop" system action cannot stop loops other than system loops. It's useful to stop iterating through the JSON if you already found what you wanted. It can optimize speed a bit, given a much bigger JSON file and components list. However it also has the drawback of making the syntax a little bit harder to read and write.

    Would you say in that case, XML would work better? If yes, does XML have the same functionality as the JSON in C3? I am asking because I did try this with XML at first (since I can understand XML a bit better) but I hit the same exact wall.

    3- loopindex("components") means the loopindex of the "components" system loop. However, it is not needed since there is only one active loop at that point. I used nested loops at first, but changed it afterward. I could have removed the ("components") part and used JSON.Get("recipes." & recipeIndex & ".components." & loopindex & ".name") instead. For the first component of the first recipe, it translates to "recipes.0.components.0.name" and returns "Wormwood". The same statement would be written "recipes[0].components[0].name" in normal javascript. C3 use a peculiar syntax to access an array's items.

    Oh! OK, I am not familiar with JS but that looks a lot like C# anyway and it does make MUCH more sense to me. Would you say it would be less of a headache if I try to write this one thing (searching for the correct component) in JS and attach it as a script instead? Because seriously I didn't have this much trouble working with JSON/XML in Unity with C# and I am very confused why it is so convoluted in C3.

  • Hey everyone,

    I am working on an inventory system and I got stuck in a tiny part. My inventory system is a "render" only system -- basically it doesn't hold any information aside from what to display and even then that is temporary. I want to know how can I loop over my dictionary keys and over all current slots of type "ingredients" for example and then change the slot animations accordingly.

    Elaborating on this, here is what I have.

    I created a sprite called "InventorySlot". It has one instance variable called "category". This identifies what kind of slot is it; weapons, potions, armor, etc...

    InventorySlot has a few animations, these animations are the icons for each of the items in the game. On the other hand I have a Dictionary called "Inventory" it has a key for every item in the game with a value referring to the amount the player has.

    What I want to basically do is this:

    For every key in the dictionary, find all InventorySlots in the layout. Set the first InventorySlot to the first key and the second InventorySlot to the second key and so forth...

    I thought this would be easy and what I tried is setup an Event with "For Each Key in Dictionary" with a Sub Event "InventorySlot > category is equal to "Weapons" and then an action "Set InventorySlot animation to Inventory.CurrentKey.

    This didn't work even though the keys and animations have the same exact names. What I got is all slots are set to the last key since the loop picks ALL InventorySlot in each iteration. So I am not sure how to tell the loop to pick one by one and set their animation and once it picks one, it skips (breaks) this iteration and moves on to the next iteration.

    Any ideas?

  • Thanks for the tip, it worked, and thanks for the fast reply too.

    Glad it worked. Good luck! :)

  • Another way to do this is to create a sprite and call it "KillTile" (or whatever you want) then set its properties to invisible. When it is set to invisible, it doesn't render in game (i.e. no one can see it) but it still acts like an object all the same with collision events and what not.

    Drag the tile on the places on the tile map that are supposed to kill the player. Then add a Payer Event > On Collision With Another Object > KillTile

    Then do your killing in the action.

  • Based on my knowledge not all events provide the option to add a local variable. However, if you encounter one of these (such as the System > On Layout Start) what you can do is add an empty sub event (using the "B" key on your keyboard while highlighting the event you want to add a sub event to) and then right click the empty sub event. You'll find the option to Add a Local Variable available. Note that anything happening BEFORE the empty sub event will not have access to the local variable.

  • Hi, Save/Load will work, but the disadvantage is that you will save all of the rest too, not just the array/dictionary. Unless you assign the "nosave" behavior to all object types.

    Check my youtube channel, it's filled with examples; for example this one. Where I use save/load, but on top of that also save load a dictionary to local storage. So both systems combined so to speak

    https://youtu.be/1EEESGQu28M

    A lot of other tutorials load stuff from arrays and dictionaries, so maybe that can help in some way too. check them out

    cheers!

    Ah, that makes sense. Forgot it saves everything. Thanks for the link that is an interesting tutorial. Learned a few things from it :D. Thank you again. I'll check the other videos!

  • As far as I know there isn't, unless someone else corrects me. But I'm guessing you're asking that because the user can change the contents during the game. I think the way you should look at this, is that the design time info is like a starting point. where you start from when starting off with the game. I think you should use the local storage plugin to save the dictionary/arrays, and on start of layout check: if the item exists in local storage, load it from local storage ELSE load it using ajax from the project file.

    but maybe I don't understand the use case well, so hope it helps?

    I think you got it right. I just wanted to save back values to the file after loading it. So say I loaded values:

    Key = potions, value = 0.

    Then player acquired 10 potions. So I save that back into the same file:

    key = potions, value = 10.

    So next time the player launches the game, the amount of potions they'd have is 10.

    I guess what you suggested should work -- will the system "Save" and "Load" actions work here too? Because I care more about saving the data than "where" to save it or must I use the local storage?

    Thanks.

  • Feeling this was right up my alley I took a stab at it using the provided recipes JSON exemple.

    I use an array to store the currently owned components. "Crafting" recipes in this exemple simply remove the components, but in real use case you'd add it to your inventory of course !

    https://drive.google.com/file/d/1F1jzwfNWpln8CbLtyPz5jnK6pyh9uwJm/view?usp=sharing

    Thanks for the .c3p. I have been reading over it and a few things went over my head, if you don't mind a few questions:

    1- The function "getRecipeIndex", is this the function that checks what kind of recipe is the player targeting? If that is the case, could you explain what is the second condition (the JSON one)? I don't understand what that does at all.

    2- Is there a reason why you're using For loops instead of For Each loops on the JSON object? Specifically in the "possibleRecipeCraftCount" function. Is it because then you can use the Stop Loop action?

    3- In "possibleRecipeCraftCount" does this line "JSON.Get("recipes." & recipeIndex & ".components." & loopindex("components") & ".name"" means Get the key that is recipes.recipeIndex.components.loopindexcomponents.name? How is that constructed? Like in my mind say first index of the loop this would mean "recipes.0.components.0components.wormwood" But I am not sure how that works in JSON. Could you explain this in plain English, please?

    4- I am guessing this line here "recipeAvailability = -1 ? 0 : recipeAvailability" is similar to C#'s terenary operator? Does this mean if recipeAvailability equals -1 then set it to 0 and if not, leave it as is?

    Thanks

  • So, Kyatric and I have had a bit more of a think about this, and if you're still interested, this blog briefly outlines the project he came up with. It also contains a download link for the project.

    At some point, I plan to turn it all into a tutorial, but that's a looong way off!

    Oh, thanks a lot Laura_D and Kyatric that definitely looks interesting and is what I wanted to do at first. I read your blog and checked the .c3p file. I can't say I understand it all -- specially the part where you're checking if the recipe exists or not. But I think I have a good overall gist of how this is done.

    I'll see if I can attempt to replicate this.

  • Hi everyone,

    I have a few dictionaries and arrays in the Files folder of my project. They were created inside C3 not imported.

    Now the information I get from those files are loaded into their respective objects at runtime. The information gets updated as the game is played.

    What I want to do is write back the information (the new updated one) into the files I read them from previously. Is there a way to do that?

    Thanks.

    Tagged:

  • Afraid I know nothing of overheads - at that point I'd usually try and create mini versions of what I was trying to test and compare the two.

    Usually I just chuck everything into as few files as possible so I only have to fetch the file once when the game/project loads. I've never tried looking at multiple files at runtime!

    It is more sensible to put all the recipes in a crafting system into one file or if the system has different categories (potions, weapons, armor, etc...) it would be each a file. But right now if they are all in one file I can't tell which recipe is which. Apparently in JSON you can't tell the For Each to stop when you found something and the System > Stop Loop action doesn't work with it. So it seems you can work with the entire lump of data not chunk it and work on pieces of it. Could be wrong though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm still getting used to working with JSON, Arrays etc so I'm kinda figuring it out as I go along, but I'll try and answer what I can!

    In terms of the For Each loops, you can nest them like this:

    See now that answers one of my big questions, how do I access the components list. I didn't know that I needed a nested For Each loop. I kept trying to use the For Each loop with "recipes/components" or "recipes.components" and neither worked. So that is interesting.

    If you don't mind a tangent question (but is definitely related); do you know the overhead of using AJAX to load a project file, do stuff with it (like checking the components listed inside and loading that file into a dictionary) then clear and load another file and so on and so forth for like 10-15 files? T

    Reason I am asking is because this is my current setup, I have a Dictionary File for each recipe, I load into a dictionary with AJAX then use the KeyCount to check if it is correct, if so, I start comparing components. Rinse and repeat for every recipe (which means every Dictionary file in the project since each recipe = a file).

    If the overhead is big, then what you just presented might actually work better -- one big JSON file that I load chunks off into a dictionary and use the dictionary's KeyCount, still won't solve the loop over the JSON 3-4 times to get what I want, but at least if AJAX has a big overhead, I saved that.

  • Not 100% sure if this will help you Vallar, but I've been messing around with crafting system ideas myself. This test project might be a bit too simple for what you're looking for, but it may give you an idea of how the JSON events could work if you wanted to go down that route. Depending on how many crafting ingredients you have, you could probably swap out the Global Variables for an Array, but I've not gotten that far yet.

    Ignore the filename, the project started as a drag/drop thing, and I've not gotten around to renaming it!

    Crafting Test Project

    Thank you very much Laura for sharing it. There are a few key differences between what I saw in your project and what I am attempting to make:

    - In my crafting system the player can slot the ingredients in any order. So before hand I have no idea what order the player will slot the ingredients in. So that requires that I loop over the ingredients in a recipe and check each ingredient separately. This is why I add all my ingredients to an array as suggested.

    - In my system, there aren't a set amount of slots to craft from. For example, right now the player has 5 slots to fill (the number of slots was completely arbitrary) so this may change in the future and the system needs to adjust for this. It could be 8 slots available or only 3. Either way, while that isn't a big deal, not all recipes use all the slots. So right now while I have 5, some recipes have 3 or even 2 slots only used. Some have the full 5.

    - In my system each of the ingredients have a specific count and if that count isn't available I can't craft. Example 10x wood + 5x stone + 50x iron will make an Iron Breastplate (absurd ingredients but it is for the sake of example). So I need the recipe to have that kind of data so I can check if the player has that amount or not.

    What your .capx showed me however is that I can loop over "recipes", I wonder however how can I loop over a list of ingredients INSIDE one of the recipes? Would it be same for each but instead I do something like "recipes/ingredients"? In that case, is there an action in the JSON object that can quickly tell me what the current ingredients count without manually iterating and adding 1 to a local variable that counts them?

    Like let's say I have this JSON:

    	{
     "recipes":[
     {
     "recipeName":"Blinding Flash Potion",
     "components":[
     {
     "name":"Wormwood",
     "count":2
     },
     {
     "name":"Sulfur",
     "count":5
     }
     ]
     },
     {
     "recipeName":"Potion of Sweet and Savory",
     "components":[
     {
     "name":"Salt",
     "count":5
     },
     {
     "name":"Sugar",
     "count":5
     }
     ]
     }
     ]
    }
    

    How do I then check the "count of components" without iterating? How to then iterate over Components for ONLY the potions that match the "count of components" I am targeting? How do I iterate over those components to confirm the name matches and then grab "count" to deduct what I want?

    Sorry for the wall of text but these are the issues that I ran into with JSON and I wasn't able to resolve/answer them.