Vallar's Recent Forum Activity

  • Good question, I haven't given that a lot of thought really...

    My first hunch would be to create the slots dynamically as well, making a grid of slots, and filling in the id's programatically, and looping as you do now. Something like that.

    Shouldn't be too hard to do, if you just set up a number of rows and columns, decide on the height and width of the slots, an offset between the slots, left margin, top margin, and you're good to go really.

    Would something like say having some placeholder sprite denote locations and then creating the slots work? So have a sprite that is invisible in each slot's location and just then spawn the slots, add their IDs and then populate the dictionary?

    I'm a pretty big fan of placeholders, as you might have noticed on some of my video's on my youtube channel, and granted that has been prone to errors, but the need for generic systems is rarely the case. Certainly not in C3 as you don't (yet) have options to integrate predefined blocks of logic.

    In my current project (or maybe this is how I am used to thinking about implementation) there are quite a few cases where generic systems would work well. For example I have two inventories; one for a shop and one for the player. Both are populated in the same exact method we've been talking about (from a predefined dictionary). So setting up a generic system here that I don't have to manually create for both ends would save a lot of hassle overall. That doesn't mean it can't be done otherwise of course (after all that is what I am doing now).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > 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:

    The Get expression of the JSON object can only return string or numeric values. The expression you written actually returns an object and C3 can't deal with that so it defaults to 0. You can however use GetAsBeautifiedString or GetAsCompactString to get objects in JSON format.

    > Would you say in that case, XML would work better?

    It's pretty much the same I would say. Altough XPath is probably easier, it has the same caveats in terms of iterating. If you use "for each node" for a particular XPath, you can't use "stop loop" and that's a bummer.

    Personally, I'm partial to JSON, simply for that fact that I find it more concise.

    > 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?

    Indeed, if you feel confortable with scripting, you could replicate what I did in a much less convulated manner.

    The JSON plugins expose an API that makes it easier to do interactions between event sheets and scripts, if you go that way.

    https://www.construct.net/fr/make-games/manuals/construct-3/scripting/scripting-reference/plugin-interfaces/json

    Thank you very much for your answers, this is very helpful. I'll give your recommendations a try and stay with JSON for a bit longer. If things get hairy, I'll see if I can try XML in hopes I could replicate the same logic but with something easier to write :)

  • I added an "id" instance variable to the slots and filled the 4 slots with number 0 to 3

    I tried something like that but instead of picking the nth instance, I set the "n" in there to loopindex but that didn't work either.

    Thank you very much for fixing it for me. I am going to use that.

    If you don't mind a side question and this purely for curiosity and nothing else -- is there a way to set it up without using the IDs or any kind of identifier?

    Reason by hind the question is that I want to understand if one can create generic systems within C3 without having to resort to IDs and what not -- to reduce the margin for human error when creating systems. If that makes any sense.

  • 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.

Vallar's avatar

Vallar

Member since 24 Mar, 2014

None one is following Vallar yet!

Trophy Case

  • 10-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

14/44
How to earn trophies