Loop Through array to set bar width

  • I'm making an RPG, I have an array with all the name and stats of each class(arr_ClassSheet). At the character select screen there is a button for each class (warrior, wizard...etc). Clicking each buttons injects data from the stats array to another array called (arr_CharacterData) so that only the name and stats for that class are used. This works all dandy :)

    However, I would like bars to display each stat (out of 100) for each class. So, if I clicked 'Warrior' the strength bar would display the Strength stat (75) out of 100. I know the maths for displaying numbers as a percentage of bar(sprite) width, however I do not know how to call the data from the array to change each bar according to the Stat.

    An easy way would be to create a bar sprite for each stat and set the value myself, but I was hoping for a quicker, less clunkier method.

    Thanks,

    Max

  • should be fairly easy to directly access the values in the main array - this is a case where I would use a dictionary to help make the code more readable.

    if you have a dictionary that has entries like: Warrior|0, Wizard|1, Knight|2...

    and entries like: Strength|0, Agility|1, Speed|2, HitPoints|3...

    then you could access the desired value like this:

    arr_ClassSheet.At(dictionary.Get("Wizard"),dictionary.get("Strength")

    (each character sprite on the screen would have an instance variable that identifies what type it is, so that can be plugged into the statement above).

    if this doesn't help, then make a small sample file for us to modify...

  • Thank you for your quick reply, I understand what you're saying and may give it a go soon.

    But what I'm asking is, for each of my 7 stats is it possible to create a button which when pressed displays all 7 stats on the screen, without creating 7 different text objects with an action:

    set text to 'arr_CharacterData.At(0,0)' ..At(0,1) etc...

    Idk much about arrays, so I was wondering If i could just loop through it and create 7 text objects when button clicked showing each stat somehow.

    Adding 7 new text objects and setting their text manually seems very long.

  • I figured it out finally and i'm super happy lol using for each and a local variable 'i'. Then setting the width to arr_CharacterData.At(0,i)

    Thank you :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • glad you figured it out!

    this is a quick sample I made to show how I might handle it...

    https://www.rieperts.com/games/forum/ChooseCharacter.c3p

  • Oh my god, so I spent about 2 days trying to come up with my solution, and there you are creating exactly what I had in mind. Wow :P

    That is honestly amazing and I'm super impressed at how you've done that with so little code as well. Thank you so much for putting your time into this for me, I'm honestly so happy and in awe xD. Thank you :)

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