How do I implement the fight bar?

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
VisualLearning
Newbie
Posts: 12
Joined: Thu Jan 07, 2016 4:30 am
Contact:

How do I implement the fight bar?

#1 Post by VisualLearning » Sun Jan 10, 2016 3:00 pm

I want to have a bar in the upper left corner that shows the value of a variable that takes an int.

I have seen how the tutorial does it but using the code gives me errors. I have looked at the Day Planner framework but don't know how to call the button or how to style it.

The closest thing I've found is here under bar:

http://www.renpy.org/doc/html/screens.html#bar

Copying the example under my init or start label does not work for me. So here are my very simple questions:

1. How do I style a bar that says "Strength" which shows a var strength out of max strength.

2. Please let me know exactly where I should put the code and under which files since this is a part of Ren'Py I am struggling with.

3. How do I call the bar and how do I remove it?

4. How do I update the bar as I update my var strength?

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: How do I implement the fight bar?

#2 Post by HB38 » Sun Jan 10, 2016 3:24 pm

Here's a really great tutorial for a 'love' bar that should be easily modified to fit your needs - I used it for experience points previously, worked like a charm.

As for where to place the code; you can throw it pretty much anywhere - Ren'Py is pretty flexible in that the order in a document doesn't matter so much (outside of the labels themselves anyhow).

VisualLearning
Newbie
Posts: 12
Joined: Thu Jan 07, 2016 4:30 am
Contact:

Re: How do I implement the fight bar?

#3 Post by VisualLearning » Sun Jan 10, 2016 3:51 pm

Thank you. How did you find the thread? Are there more like it?

I do not wish to use custom visuals but the existing game interface. Doesn't the game have a way to create bars? I thought it would be simple.

I still don't know how to style a bar, call it or have it go away. I don't know how to make it display values that it gets from a var. I have read the thread over and over again and still don't understand which parts of the code I need to use and how I can change it to fit my request.

Seeing how there is no deeper explanation of the code I do not know how to write my own adaptation from scratch.

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: How do I implement the fight bar?

#4 Post by HB38 » Sun Jan 10, 2016 4:13 pm

I found it via a quick search, but it's also located in the cookbook directory thread.

You can probably replicate the feature using solid colors and boxes, but I would imagine just whipping up very basic graphics would still be easier.

You'd want to place the bar on it's own screen and then call and hide the screen as needed. The tutorial uses a variable to pull ($ show_giselle=True) it back and forth which could also be handy, but I prefer using screens.

Looking over the code, there is already a bar present and it's taking the graphics and just "applying them" - I'm not super familiar with them (as I've always made my own graphics) but it may be possible to forgo that step.

As for reading the code… well, I guess I'll just answer the one question you mention (the displaying of vars). Here is the bit from that tutorial where it takes the values and applies them to the bar:

Code: Select all


    def stats_overlay():               
        
        # --- Giselle's Love Bar -------
        if show_giselle:
            ui.frame(
                xalign = 0.5, #centered
                ypos = 400,) #400 px Down from the Top
            
            ui.vbox(xalign = 0.5)
            ui.text ("Giselle's Love Points: %d" %giselle_love, 
                xalign = 0.5)
            ui.bar(max_love, giselle_love, 
                style="my_bar")
            
            ui.close()
 
The area with ui.text is where it outputs the words, and %giselle_love is the variable (you'd use %current_strength here or whatever your var is called).

The area with ui.bar has the values of %max_love (the maximum the bar can get to), and %giselle_love (which is the value of the stat). You'd probably change those to %max_strength and %current_strength for your code.

The rest of the code is for just where it's being displayed on the page, if you're unsure what it's doing I'd just change one value and a time and reload your project (shift - R if developer mode is on) to see where things move and go from there.



If you feel truly lost, I would recommend creating a new project and copy/pasting the entire tutorial in there, run it… then just start changing things. At least, that's how I work best.

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: How do I implement the fight bar?

#5 Post by HB38 » Sun Jan 10, 2016 4:24 pm

Did some more digging, here is a bar using the built in methods that may be a bit easier for you to modify.

VisualLearning
Newbie
Posts: 12
Joined: Thu Jan 07, 2016 4:30 am
Contact:

Re: How do I implement the fight bar?

#6 Post by VisualLearning » Sun Jan 10, 2016 4:58 pm

Good advice regarding creating a new project but sometimes I get confused about how to even implement the code.

The second thread was perfect. The code is simple and I clearly understand what each part does which helped me create what I wanted.

I really appreciate your help and patience!

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: How do I implement the fight bar?

#7 Post by HB38 » Sun Jan 10, 2016 5:08 pm

VisualLearning wrote:Good advice regarding creating a new project but sometimes I get confused about how to even implement the code.

The second thread was perfect. The code is simple and I clearly understand what each part does which helped me create what I wanted.

I really appreciate your help and patience!
I'm not really a coder myself (and am more of a visual learner, actually… so har!) so seeing code and then monkeying with it is how I tend to work things out myself. Glad that was what you were looking for!

Post Reply

Who is online

Users browsing this forum: Ocelot