Page 1 of 1

the quietest shrieking over a simple stats menu [solved]

Posted: Fri Feb 13, 2015 7:28 pm
by queergames
so here's the deal: i'm making a game which has a small stats menu on the top right. seems easy, yes? apparently not. i don't even want to show you guys the code because i KNOW that it's a mess. i've never used screens before and it really shows. i've already tried nabbing someone else's python code, and you can imagine how that's going for me.

what i need the stats to do is the following:
display the level (which changes based on exp. so if your exp is less than 21, you're level 1. between 21 and 50, you're level 2, etc. but it needs to display the LEVEL and no the EXP)
display a bar (which ive figured out) which has a max of 100. if the value reaches 100, the game ends.
display money. which should be simple, but i've been so stuck on the level thing i could scream.

code is below if you really must see it, but like i said... it's essentially useless.

thanks in advance for your patience with me.

SOLUTION:

Code: Select all

init python:
    def add_dys(d):
        store.dys += d
        if store.dys > 100:
            renpy.jump("game_over") #this code makes it such that if the "dys" value goes over 100, the game ends and jumps to the scene labeled game over

# The game starts here.
label start:

    $ exp = 0
    $ dys = 0
    $ money = 10

    show screen stat_menu

screen stat_menu:
    frame:
        align (1.0, 0.0)    #this aligns the stat box to the top right     
        xmaximum 200 #this sets the maximum width of the box
        background "#393939" #this sets the background colour an image can also be used
        has vbox
        if exp <= 20:
            text "Level 1"
        if exp >= 21 and exp <= 50:
            text "Level 2"
        if exp > 51:
            text "Level 3"
        bar value dys range 100 #this creates the dysphoria bar
        text "Money: [money]"

"Blah blah blah."

"Hey there!  Before we get started, why not tell us your name?"
    
$ povn = renpy.input(_("Type your name and press return/enter.")) or _("Player")
    
"oh my god."
    
$ add_dys(10)
    
"In theory, dysphoria should go up."
    
$ exp += 21
    
"Level should increase to 2."

return

label game_over:
    
    "Adrien\'s dysphoria got too high.  Game over!"

return

Re: the quietest shrieking over a simple stats menu

Posted: Fri Feb 13, 2015 9:32 pm
by SundownKid
You should check out Screen Language, this is outdated code. Current documentation is here: http://www.renpy.org/doc/html/screens.html

It should be something more like:

Code: Select all

label start:
     $ exp = 0
     $ dys = 0
     $ money = 0
     n "Blah blah blah"
     show screen stat_menu

screen stat_menu:
    vbox:
        xalign 1.0
        yalign 0.0
        xysize (300,300)
        if exp < 21:
            text "Level 1"
        if exp > 21 and exp < 50:
            text "Level 2"
        if exp > 50:
            text "Level 3"
        bar value "dys" range 100
        text "Money: [money]"
I'm not sure if it will totally work but it should be something like that.

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 2:04 am
by queergames
Thanks. That worked, I think. Now I just need to make it have a background and limit the size. xysize produced an invalid syntax error.

Ugh. I am so not a coder.

edit: also it seems like dysphoria is stuck at 100? i think i can fix that myself, but the size and the clear background are still problems. i've tried reading the linked page, but i can't process any of it because it's not really that clear.

edit 2: hm. the level display is also not working. it works for level 1 but disappears after that.

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 8:26 am
by xavimat
The "if" statements are missing the numbers 21 and 50:

Code: Select all

if exp < 21:   # what if exp == 21???
            text "Level 1"
if exp > 21 and exp < 50:  # what if exp == 21 or == 50 ???
            text "Level 2"
if exp > 50:
            text "Level 3"  # what if exp == 50???
I suggest:

Code: Select all

if exp < 21:
            text "Level 1"
elif exp < 51:
            text "Level 2"
else:
            text "Level 3"

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 2:40 pm
by queergames
xavimat wrote:The "if" statements are missing the numbers 21 and 50:

Code: Select all

if exp < 21:   # what if exp == 21???
            text "Level 1"
if exp > 21 and exp < 50:  # what if exp == 21 or == 50 ???
            text "Level 2"
if exp > 50:
            text "Level 3"  # what if exp == 50???
I suggest:

Code: Select all

if exp < 21:
            text "Level 1"
elif exp < 51:
            text "Level 2"
else:
            text "Level 3"
I've figured out the levels by simply using <= (something I've done for another project) but the screen still has no background and is stretched across the entire game. Is there some properties I'm missing or don't understand which control these things?

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 3:06 pm
by trooper6
Hi queergames,

In my game I have a panel that hangs out over on the right side of the screen. It has a background (which in my case is an image) and has very specific dimensions. I did this using style properties.

The screen looks like this:

Code: Select all

screen control():
    frame:
        style_group "game"
        xalign 1.0
        yalign 0.0
The screen then has some vboxes and some buttons, etc. (Not important for this example).

Then somewhere else I define the style. In this case I have defined it after the screen, but you could do it before I suppose:

Code: Select all

style game_frame is default:
    background Frame("00 images/00Intertitle2_64x71.png", 64, 71)
    xmargin 10
    ymargin 10
    xminimum 250
    yminimum 748
    xmaximum 250
    ymaximum 748
Hope that helps!

ETA: You don't have to give it a special style of course. You could just define it in your element directly. I do have a frame that I've specified its ymaximum like so:

Code: Select all

frame:
    ymaximum 160
    add myClock xanchor 0.5 yanchor 0.5

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 5:48 pm
by xavimat
Sundowkid's solution using frame, as trooper6 suggests:

Code: Select all

screen stat_menu:
    frame:
        align (1.0, 0.0)        
        xysize (300,300)
        background "bg_stat.png"
        has vbox
        if exp <= 20:
            text "Level 1"
        if exp > 20 and exp <= 50:
            text "Level 2"
        if exp > 51:
            text "Level 3"
        bar value "dys" range 100
        text "Money: [money]"
Some explanation:
- Using frame because has the background property to add an image (and vbox hasn't it).
- align (#, #) is the same that adjusting separately xalign and yalign
- xysize doesn't throw an error if correctly indented and with the parenthesis. I'd suggest here the same size as the background image. Actually, xysize is the same that setting separately xmaximum, xminimum, ymaximum, yminimum.
- has vbox adds a vbox inside the frame, to set the following elements vertically.

EDIT:
if the value reaches 100, the game ends
This has nothing to do with the screen stat_menu, used only to display the info, not to check it. You need a separate way (maybe a function) to checkt. My suggestion (not tested):

Code: Select all

init python:
    def add_dys(d):
        store.dys += d
        if store.dys > 100:
            renpy.jump("game_over")

label start:
    $ dys = 0
    # in your game don't use:
    # dys += 20
    # because it won't be checked.
    # Instead, dys is increased using:
    $ add_dys(120)
    
    # ...      
    
label game_over:
    "END"
    $renpy.full_restart()

Re: the quietest shrieking over a simple stats menu

Posted: Sat Feb 14, 2015 7:33 pm
by queergames
Perfect! I figured it all out and it's working perfectly. Thanks so much to everyone.