Data Table Screen with looped output + scrollbar

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
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Completed: Monochrome Valentine
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Data Table Screen with looped output + scrollbar

#1 Post by zankizuna »

Hi lemmasoft, and PyTom! if you see this :)

I'd like to make a data table screen...
the info will be based on the values of a list.
My renpy game saves player's scores into a database.
I manage to do requests and post data, but now I need to output it properly.
The data to be shown is affected by the players who registered.
I have this code that gets data,
The SQL codes return the info of the players, so a player can use the renpy game to see a "Leaderboard".
the return values look a little like this.

[{"id":"74","email":"zankizuna@yahoo.com.ph","username":"Zan","gender":"Male","gamelevel":"5","gamescore":"523","studentnum":13001253600"},{"id":"87","email":"breezetheeraser@gmail.com","username":"Breeze","gender":"Female","gamelevel":"10","gamescore":"13868","studentnum":"17004883647"},{"id":"102","email":"raseruuu@gmail.com","username":"Raseru","gender":"Male","gamelevel":"3","gamescore":"24","studentnum":"15001401912"}]

Do I have to dissect this as a string so I can print them into the screen?
I want it to look kinda like this...
Screen shot 2017-02-24 at 7.38.22 PM.png
Screen shot 2017-02-24 at 7.38.22 PM.png (12.53 KiB) Viewed 914 times
and if the data is too long, a scrollbar will be useful.
I know renpy kinda did it in tutorial.rpy, but it was hard for me to understand.
If possible, I'd like to use it with a for loop.
Thanks in advance!!

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Data Table Screen with looped output + scrollbar

#2 Post by PyTom »

I'm assuming you've already turned the JSON into python objects (using json.loads). So then you just do:

Code: Select all


screen leaderboard(data):
    vbox:
        hbox:
            text "Username" xsize 200
            text "Score" xsize 100
            text "Level" xsize 100
            text "Rank" xsize 100

        for i, u in enumerate(data):

            $ rank = i + 1

            hbox:
                text "[u[username]]" xsize 200
                text "[u[gamescore]]" xsize 100
                text "[u[gamelevel]]" xsize 100
                text "[rank]" xsize 100
Note that since people can grab the raw data, so sending emails, ids, studentnums, etc might be a bad idea.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: No registered users