Energy bars and Stat menus question

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.
Message
Author
Feliciaty111
Newbie
Posts: 2
Joined: Wed Jun 03, 2015 4:39 pm
Tumblr: Little-Darkrai
Contact:

Energy bars and Stat menus question

#1 Post by Feliciaty111 »

So here's my problem. I have looked at almost everything on either of these subjects and yet every code I've tried to replicate seems to just pop up with errors either with just silly things like not defining variables to game crashing things like 'Not a valid name or child of ""'. I find it more helpful to see these two things in action in a script other then just a stand alone code.

I pretty much want to make an energy bar that shows up at the corner of the screen. A stat menu, like charisma points you have and strength points you have, and a button to click on to open it up.

I just started using Ren'py roughly two weeks ago, but I'm not exactly new to python coding. But this is the first problem I ran into that I can't seem to overcome on my own. Is there maybe a chance there are completed scripts out there with either of these things on them that I can look at? Or maybe point me to a in depth tutorial?

Any help would be good! Thanks :)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Energy bars and Stat menus question

#2 Post by xela »

Code: Select all

screen meow():
    vbox:
        align (1.0, 0)
        spacing 10
        bar:
            xsize 200
            value stats["HP"]
            range 100
        
        frame:
            xsize 200
            has vbox
            for stat in sorted(stats.keys()):
                fixed:
                    xysize (180, 20)
                    text "[stat]:" xalign 0
                    $ stat = stats[stat]
                    text "[stat]" xalign 1.0
    
label start:
    $ stats = {"HP": 50, "MP": 30}
    show screen meow
    pause
Like what we're doing? Support us at:
Image

Feliciaty111
Newbie
Posts: 2
Joined: Wed Jun 03, 2015 4:39 pm
Tumblr: Little-Darkrai
Contact:

Re: Energy bars and Stat menus question

#3 Post by Feliciaty111 »

Thank you! I was actually able to take a few pieces from that and wow, it actually worked thanks :lol:

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#4 Post by UselessCoder »

xela wrote:

Code: Select all

screen meow():
    vbox:
        align (1.0, 0)
        spacing 10
        bar:
            xsize 200
            value stats["HP"]
            range 100
        
        frame:
            xsize 200
            has vbox
            for stat in sorted(stats.keys()):
                fixed:
                    xysize (180, 20)
                    text "[stat]:" xalign 0
                    $ stat = stats[stat]
                    text "[stat]" xalign 1.0
    
label start:
    $ stats = {"HP": 50, "MP": 30}
    show screen meow
    pause

I'm trying to understand and customize this script, and what I got so far is:

the stats are merged into a single block:

Code: Select all

$ stats = {"ENE": 100, "KNO": 0, "CHA": 0, "APP": 0,}
the "nested" values of that statement define the bar lenght.

Now there are two things I haven't understood even after checking the renpy documentation in regards of the init chapter and vbox customization, for it seems it's something not being covered:

1.how do I actually "call" a nested value in order to increase it? Everything I tried so far returned a variety of errors.
If I call the single parameter (i.e. $ ENE +=10) it says (of course) that it's not defined.
I've also tried something like "$ stats +=10", maybe thinking that every stat would've increased by 10, but it returned me an error.

2. Is it actually possible to customize the bar in order to show what value it refers to (i.e.: "ENE") along with the current level (i.e.:"34/100") and make this line of text following the bar as it increases/decreases?
I've checked various threads concerning bars and apparently none of them mentions such possibility, so I guess you cannot display any text over a bar. Unless you create a different frame containing the text and actually overlay it to the bar through zorder? That would look like such a messy solution anyway.

Thanks for giving me some explanations :)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Energy bars and Stat menus question

#5 Post by xela »

1)

Code: Select all

$ stats["ENE"] += 10
2)

I understand what you're asking but don't understand why you're having problems, bars are nothing special, you can put texts with name and values at any position near or even right on top of them using the normal positioning rules...
Like what we're doing? Support us at:
Image

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#6 Post by UselessCoder »

xela wrote:1)

Code: Select all

$ stats["ENE"] += 10
2)

I understand what you're asking but don't understand why you're having problems, bars are nothing special, you can put texts with name and values at any position near or even right on top of them using the normal positioning rules...

Thanks Xela...So I was right, meaning that the only way is positioning another piece of text...Uhm. Don't know if that's worth after all, I'll probably go with a frame containing them.

As for the code...I can make it work as a statement, but not as part of a condition:

Code: Select all

      "test stats for 100 euros!":
            
            if $ stats ["ENE"] =0:
                "No can do. I'm too tired, I need some sleep..."
            jump home
            elif $ stats ["ENE"] >=0:    
                 "You've earned 100 euros!" 
            $ mod_money (100)
            $ stats ["KNO"]+=10
            $ stats ["ENE"]-=10
            
            jump home

There's a syntax error but don't understand why...Anyway as soon as I get to understand how it works, I believe I'm gonna figure out how to create a function for this...Writing all of this stuff under every action affecting stats makes the whole code look messy and endless...But that's extremely OT now.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Energy bars and Stat menus question

#7 Post by mobychan »

If you're checking values use two equal signs and no need for the $:

Code: Select all

           if stats ["ENE"] == 0:
                "No can do. I'm too tired, I need some sleep..."
            jump home
            elif stats ["ENE"] >= 0:    
                 "You've earned 100 euros!" 

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#8 Post by UselessCoder »

mobychan wrote:If you're checking values use two equal signs and no need for the $:

Code: Select all

           if stats ["ENE"] == 0:
                "No can do. I'm too tired, I need some sleep..."
            jump home
            elif stats ["ENE"] >= 0:    
                 "You've earned 100 euros!" 
Thanks! it perfectly worked like this:

Code: Select all

        "test stats for 100 euros!":
            
            if stats ["ENE"] == 0:
                $ stats ["ENE"] = 0
                "No can do. I'm too tired, I need some sleep..."
                jump home

            if stats ["ENE"] >= 0 and stats ["KNO"] < 100:
                "You've earned 100 euros!" 
                $ add_money (100)
                $ stats ["KNO"]+=50
                $ stats ["ENE"]-=10
                jump home
            
            if stats ["KNO"] == 100:
                $ stats ["KNO"] = 100
                "You've earned 100 euros, although you couldn't improve your skill level."
                $ add_money (100)
                $ stats ["ENE"]-=10
                jump home
Now comes the "fun" part of it: turning all of this into a function...Needless to say, I'm totally clueless but I'll try to figure out.
Thanks for now!

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#9 Post by UselessCoder »

Nothing...it seems like I cannot call the stats from the statement. I know it is just me but it's kinda getting frustrating now. lol

tried this:

Code: Select all

    hbox: 
        spacing 10 xpos 1145 ypos 78
        text "{color=#FFFFFF}{size=-6} $ stats[KNO]/[max_kno]{/size}{/color}" 
and multiple variations of that...but nothing... :x

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Energy bars and Stat menus question

#10 Post by xela »

Code: Select all

hbox:
        spacing 10 xpos 1145 ypos 78
        $ s = stat["KNO"]
        text "{color=#FFFFFF}{size=-6}[s]/[max_kno]{/size}{/color}" 

May I suggest at this point that you take some time to go through the documentation and read a couple of post on the subject? There are posts and docs covering interpolation, python one liner statement, container iterations, dictionaries and styling, both through style declarations and direct supplying of properties through the screen language.

(In the end) It shouldn't be a matter of trying multiple variations, but of understanding of what you're doing, and that doesn't seem to be improving :(

My best suggestion is to try and learn the basics of Python and Ren'Py before trying to move forward with your project. Dictionaries are as basic as Python gets and Ren'Py interpolation has been discussed in great detail on the forum. Python statement and python one liner are also very well covered in the docs.
Like what we're doing? Support us at:
Image

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#11 Post by UselessCoder »

xela wrote:

Code: Select all

hbox:
        spacing 10 xpos 1145 ypos 78
        $ s = stat["KNO"]
        text "{color=#FFFFFF}{size=-6}[s]/[max_kno]{/size}{/color}" 

May I suggest at this point that you take some time to go through the documentation and read a couple of post on the subject? There are posts and docs covering interpolation, python one liner statement, container iterations, dictionaries and styling, both through style declarations and direct supplying of properties through the screen language.

(In the end) It shouldn't be a matter of trying multiple variations, but of understanding of what you're doing, and that doesn't seem to be improving :(

My best suggestion is to try and learn the basics of Python and Ren'Py before trying to move forward with your project. Dictionaries are as basic as Python gets and Ren'Py interpolation has been discussed in great detail on the forum. Python statement and python one liner are also very well covered in the docs.

Well I guess the case is pretty much different here, xela.
I'd surely need to go through a lot of documentation, not just the ones you mentioned. And partially I did already.
The thing is, it appeared to me that none of the topics I red on (say) interpolation "discussed in great detail" such cases as having a statement with multiple values like $ statement= {"one": 100, "two": 0, "three": 0,} and needing to format just one of those values through an hbox.
I mean documentation would certainly cover a lot and tell you the basics (it's all about brackets, how cool! :D ) but I guess that anything else means going an extra mile that doesn't just take "some time" but a lot of time. And experience. Which I don't have and never will in the near future, since I'm an artist and this project is something that happened now for fun, not the beginning of any career in this industry.
So, I guess I'm gonna happily split the multiple statement into maaany single statements and be happy with the fool way of coding.
Thanks anyway.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Energy bars and Stat menus question

#12 Post by mobychan »

What seems to be lacking is your understanding of ground level basics
If you start understanding the basics, it's easy to find errors in your code.
Like xela said, it should be about trying something randomly, but about using your basics.

If you're not interested in doing this, go ahead and hire a coder to do it for you.
Those guys and gals already learned their basics, and far more than those.

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#13 Post by UselessCoder »

mobychan wrote:What seems to be lacking is your understanding of ground level basics

Well Mobychan, I followed xela suggestion and, according to the solutions given in the topics, some of the authors shown pretty much the same "lacking of understanding". But other than that, I couldn't find anything related to such a specific issue, so either I'm stupid (which btw it's a concrete possibility :lol: ) or the matter wasn't "discussed in (a sufficiently) great detail".

But anyway, like I said, everyone's free to give those solutions or lecturing instead, I was never expecting/begging for that or giving it for granted.
Just a question. And I've got my answer. :)

Thanks. ;)

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Energy bars and Stat menus question

#14 Post by UselessCoder »

Anyway I've found out the solution to my problem on my own:

Code: Select all

[stats[ENE]]
.

That's was what all the fuzz was about. I post it here for anyone who might have issues with it, or showing symptoms of "lacking of understanding" and because that's what I believe a forum spirit should be like.

Before I leave, there's just one more thing you guys don't know about me.
I've been an artist for like the last 20 years.
I do help a lot of wannabe artists on art forums.
Most of the times I take my time off to sketch doodles for them in order to make them understand how to fix their problems.
And believe me, they often come up with issues of the most basic kind such as perspective and anatomy.
But regardless of how "basic" their needs might be, I've never suggested them to take art classes or to hire someone.
I do that for free and for the sake of knowledge sharing.
Now you're totally free to do otherwise, but I'm free as well to point out that's a very selfish and somehow rude behaviour.
But anyway, like I said, anyone's free to behave as he's more comfortable with.

Thanks for reminding me what kind of person (and artist) I am. :D

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Energy bars and Stat menus question

#15 Post by xela »

UselessCoder wrote:Anyway I've found out the solution to my problem on my own:

Code: Select all

[stats[ENE]]
Accessing dict through a variable creating a list in the process, if this is the exact, actual code you've ended up with, than that's what all the "fuss" was about.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: No registered users