What is the best data structure for crafting and how to create it?

0 favourites
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • Oh sure. It takes the file and uses the tokenat expression to look at it a line at a time.

    One event sees if the line starts with #recipe, if it does it uses the rest of that line as the name of a new recipe.

    The other event handles either blank lines or lines that have a number followed by an ingredient name.

    Left() gets the left side of some text

    Mid() gets the middle

    Trim() removes any leading and trailing spaces in the text.

    Finally it keeps track of the uid of the last recipe created. That is just so we can pick it again when adding ingredients to it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > The path you are using is not correct

    >

    > JSON2.get(".recipes" & loopindex) probably will work

    > It depends on the content of your json file though.

    Interesting. Thank you for pointing that out. Does this mean that the parent "JSON part" (like the parent header) must have a "." before it? I thought it didn't need that, since it is at the very top.

    No, your path is correct, but returns an object like I mentionned earlier, and you can't use "Get" to retrieve its content. Top level absolute path never begins with ".", you only ever begin your path with "." when you are working with relative paths, like in a "for each" or by using the "Set path" action.

  • Oh sure. It takes the file and uses the tokenat expression to look at it a line at a time.

    One event sees if the line starts with #recipe, if it does it uses the rest of that line as the name of a new recipe.

    The other event handles either blank lines or lines that have a number followed by an ingredient name.

    Left() gets the left side of some text

    Mid() gets the middle

    Trim() removes any leading and trailing spaces in the text.

    Finally it keeps track of the uid of the last recipe created. That is just so we can pick it again when adding ingredients to it.

    Thank you for the explanation. If you don't mind a few questions just to make sure I understand this correctly.

    * When the event says "recipe > Set name to mid(line, 8, 100)", are you basically extracting the name of the recipe? You're using "mid" here since "left" is = to #recipe? Wouldn't "8" here count the space just before the recipe's name? Or does it ignore it? Also if you don't mind why 100? Is it arbitrary long so you can capture whatever name is here?

    * In the Else statement, there is System > Set count to int(line). The way I understand it is, line is equal to the current sentence (so in case of an ingredient for example "2 wormwood") how does int(someString) know what to grab as a number? I thought the "int" expression just approximates a float into an int?

    * In the same Else statement there is a line that says System > Set ingredient to trim(mid(line, len(str(count)), 100)). Does this basically says "Trim the current line from spaces leading and ending" Then you check the middle part, that starts right after "how many count is in characters" and for 100 characters long? This goes back to the first question. If len(str(count)) is equal to 1 (because count is going to be the one number at the left of the recipe) then again, wouldn't that return " wormwood" instead of "wormwood"? I know you used Trim to negate if this happens, but you didn't use it in the other one, this is confusing to me.

    Thanks.

  • > > The path you are using is not correct

    > >

    > > JSON2.get(".recipes" & loopindex) probably will work

    > > It depends on the content of your json file though.

    >

    > Interesting. Thank you for pointing that out. Does this mean that the parent "JSON part" (like the parent header) must have a "." before it? I thought it didn't need that, since it is at the very top.

    No, your path is correct, but returns an object like I mentionned earlier, and you can't use "Get" to retrieve its content. Top level absolute path never begins with ".", you only ever begin your path with "." when you are working with relative paths, like in a "for each" or by using the "Set path" action.

    Thanks for re-confirming that, Kyatric threw me off.

  • mid(line, 8, 100) is extracting the name. It starts at character 8 since “#recipe” has a length of 7 and I added 1 more to skip the space after it too. 100 is just arbitrary. I just needed something well over the length of the line. It basically just gets the rest of the line.

    int() also converts text to a number. It just gets any digits and then stops when it hits anything else.

    I used it as a shortcut to just grab the number at the beginning of the line.

    I turn it back into text and get it’s length so I can know what character to start at for mid.

    I guess I wasn’t consistent to use trim. I could very well have added 1 to account for the space

    mid(line, len(str(count))+1, 100)

    The trim is nice to use though. Gets rid of any unintentional trailing spaces.

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