Loop Through array to set bar width

0 favourites
  • 6 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • 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.



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


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

  • Try Construct 3

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

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

  • glad you figured it out!

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


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