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

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
yon
Regular
Posts: 174
Joined: Tue Sep 09, 2014 5:09 pm
Projects: YDSP
Soundcloud: tetra-yon
itch: v-ual
Location: United States
Contact:

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

#1 Post 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?
Attachments
statbox.png
statbox.png (5.69 KiB) Viewed 379 times
Last edited by yon on Tue Aug 16, 2022 5:21 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

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

#2 Post 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.
< < insert Rick Cook quote here > >

User avatar
yon
Regular
Posts: 174
Joined: Tue Sep 09, 2014 5:09 pm
Projects: YDSP
Soundcloud: tetra-yon
itch: v-ual
Location: United States
Contact:

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

#3 Post 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.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

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

#4 Post 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.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users