Page 1 of 1

[Solved] Making a variable in a screen dependent on another variable?

Posted: Mon Aug 15, 2022 7:00 pm
by yon
Hi all,

I'm trying to create a bar in a screen to display a character's stats. That's all well and good, except the bar isn't a single solid block, but rather, 5 dots. I've included the background UI to show where the dots go.

I can make the bar show the image like normal, but I didn't like how it was displaying the progress, because it isn't actually 1:1 in terms of where the progress is. That is, having a stat whose value is 20 out of 100 should fill up the first dot, but it doesn't, because it's not proportional to progress.

So, what I WANT to do is find a way to set the value of the bar to increments of the character's stats. That is, if the character's stat is at 20, I set the value to make the bar display 10 pixels. If the stat is at 40, display 25 pixels.

The stat value goes up to 100, and the max length of the bar UI image is 70 pixels.

Each increment is as follows:
  • 20 points - 10 px
  • 40 points - 25 px
  • 60 points - 40 px
  • 80 points - 55 px
  • 100 points - 70 px
I could even break it down further to show the pixel value for increments of 10 points as well.

I know how to do a simple "if then" statement, like, theoretically, this would change the value of the bar's length variable based on the stat variable:

Code: Select all

if $ v_mind >= 100:
    $ bar_mind = 100
elif $ v_mind >= 80:
    $ bar_mind = 80
elif $ v_mind >= 60:
    $ bar_mind = 60
elif $ v_mind >= 40:
    $ bar_mind = 40
elif $ v_mind >= 20:
    $ bar_mind = 20
else:
    $ v_mind = 0
Note: bar_mind = the variable which determines length of the bar for the Mind stat, and v_mind is the variable for the Mind stat.

The real question is, how do I do this in terms of a screen? Where do I put that code? I've tried putting it into the screen code, but it gives me an error, which is expected. Am I supposed to be doing something else?

Should I just make the bar a solid line instead of dots and avoid making it complicated?

Re: Making a variable in a screen dependent on another variable?

Posted: Tue Aug 16, 2022 4:26 am
by Ocelot
In your case it is better to not make this complicated and simply add 5 empty pixels to the left part of bar image, so everything start being proportional.

Re: Making a variable in a screen dependent on another variable?

Posted: Tue Aug 16, 2022 5:21 pm
by yon
I think what I'll do is change it to a solid bar with accurately proportional progress markers. That might be even easier, at least, in terms of making it clear how progress you've made.

Thank you again for the help, Ocelot.

Re: [Solved] Making a variable in a screen dependent on another variable?

Posted: Tue Aug 16, 2022 7:30 pm
by Imperf3kt
One method not suggested would be to have a regular bar displayed, and layer a mask above it, so only the dots are transparent. As the bar fills, it shows through where the dots are, but nowhere else.
Kind of like taking two sheets of paper, drawing on one and cutting a hole in the other then trying to look through the cut paper.