Updatable variables (Solved)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Popotan
Newbie
Posts: 3
Joined: Wed Feb 10, 2016 12:46 pm
Contact:

Updatable variables (Solved)

#1 Post by Popotan »

It's me again, writing tips for those who are not familiar with python, but want to make a game with lots of variables. If you are one of that kind of developers, you may wonder - "How to make some variables dynamically updatable (Based on some conditions) on a screen?" The thing is - you must write a custom function for that. Those are a little hard to catch at first, but I'll give you a nice example here.
For example, you made a height slider for character creation screen.

Code: Select all

init:
    $ height_cm = 0
    $ height = " "
init python:
    def height_calc():
        if height_cm <= 150:
            height = "Low"
        if height_cm > 150:
            height = "Average":
        if height_cm > 180
            height = "Hight":
        return height

screen character_creation:
    $ height = height_calc()
    frame xalign 0.5 yalign 0.5:
        has vbox xalign 0.5
        text "Choose your height"
        bar xmaximum 300:
            value VariableValue("height_cm", 200)
            style style.slider
        text "Your height is [height_cm] cm ([height])"
        hbox xalign 0.5 yalign 0.9:
    textbutton "Accept" xalign 0.99 action Jump("start")
That way you will immeadiately see on screen how properties of your height are updated. And you must define all the conditions only once in init section. If you need those in any other screen, everything you need is to assign "$ variable = function()" as a first line of the screen code. I hope it will help somebody.

Post Reply

Who is online

Users browsing this forum: No registered users