[Solved] Any example for creating a battle log on the screen?

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
wanyc
Newbie
Posts: 5
Joined: Mon Jul 01, 2019 6:37 am
Contact:

[Solved] Any example for creating a battle log on the screen?

#1 Post by wanyc »

I was thinking about create a battle log screen/window on the right side of the game, recording things such as "xx attack you and you dodged", "you attack xx and xx lost 4 health points" something like that. When the information is too much, a scrollbar would appear.
I think it is quite similar to dialogue history, but it is on the same screen of the game. My first thought was using vbox, I check the instruction and found that you need to add text beforehand, not automatically with games. besides there is no mention of scrollbar. So I am wondering is there any example I can follow? Or this kind of log system is just impossible for renpy. Thanks.
Last edited by wanyc on Fri Jul 12, 2019 12:04 am, edited 1 time in total.

User avatar
Enchant00
Regular
Posts: 136
Joined: Tue Jan 12, 2016 1:17 am
Contact:

Re: Any example for creating a battle log on the screen?

#2 Post by Enchant00 »

It really depends on your battle system, but for what you're trying to achieve you can use screens for it https://www.renpy.org/doc/html/screens.html such as using a blank frame for the box then you populate it later with data. As for the scroll part, you can use the viewport to make it https://www.renpy.org/doc/html/screens.html#viewport and in the renpy cookbook you should be able to find tutorials on scroll bars. As I said earlier, it will really depend on your battle system.

wanyc
Newbie
Posts: 5
Joined: Mon Jul 01, 2019 6:37 am
Contact:

Re: Any example for creating a battle log on the screen?

#3 Post by wanyc »

Enchant00 wrote: Wed Jul 10, 2019 5:17 am It really depends on your battle system, but for what you're trying to achieve you can use screens for it https://www.renpy.org/doc/html/screens.html such as using a blank frame for the box then you populate it later with data. As for the scroll part, you can use the viewport to make it https://www.renpy.org/doc/html/screens.html#viewport and in the renpy cookbook you should be able to find tutorials on scroll bars. As I said earlier, it will really depend on your battle system.
Thanks a lot, I am gonna try this. Do you happen to know the code to populate data? I check the page of screens several times and I couldn't find it.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Any example for creating a battle log on the screen?

#4 Post by xavimat »

You can try this (not tested):

Code: Select all

default histo = []

init python:
    def log(txt):
        histo.append(txt)
        renpy.hide_screen("myhistory")
        renpy.show_screen("myhistory")
        
screen myhistory():
    viewport:
        mousewheel True
        draggable True
        scrollbars "vertical"
        yinitial 1.0
        vbox:
            null height 10
            for i in histo:
                text i
                
label start:
    $ log("Troll insults you, -5HP.")                
    pause
    $ log("You punch Troll, -2HP.")
    pause
    $ log("Troll punches you, -500000HP.")
    pause
    $ log("GAME OVER")
    pause
    return
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

wanyc
Newbie
Posts: 5
Joined: Mon Jul 01, 2019 6:37 am
Contact:

Re: Any example for creating a battle log on the screen?

#5 Post by wanyc »

xavimat wrote: Wed Jul 10, 2019 11:32 am You can try this (not tested):

Code: Select all

default histo = []

init python:
    def log(txt):
        histo.append(txt)
        renpy.hide_screen("myhistory")
        renpy.show_screen("myhistory")
        
screen myhistory():
    viewport:
        mousewheel True
        draggable True
        scrollbars "vertical"
        yinitial 1.0
        vbox:
            null height 10
            for i in histo:
                text i
                
label start:
    $ log("Troll insults you, -5HP.")                
    pause
    $ log("You punch Troll, -2HP.")
    pause
    $ log("Troll punches you, -500000HP.")
    pause
    $ log("GAME OVER")
    pause
    return
Thanks a lot! This is exactly what I want, although "pause" freezes the screen and would not recover no matter what I click so I cannot test the scroll part. Anyway, I think I don't need pause in my game so that is just fine. Thanks again

Post Reply

Who is online

Users browsing this forum: No registered users