Displaying Class Variable In 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
Nero
Veteran
Posts: 237
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Displaying Class Variable In Screen

#1 Post by Nero » Sat Mar 14, 2020 12:09 pm

I have made a Class variable which holds 2 values. One is skill_damage and other is skill_description which shows skill damage with operator %s . Now problem is that whenever I update skill_damage the description %s damage stays the same even if the skill_damage value is changed this visual text display does not update. So how do I make screen update skill_damage value every time it changes?


This is what i mean:

Code: Select all

init python:
    class Skill(object):
        skill_damage = 5
        skill_description = "Deal %s damage!" % skill_damage

    def add_dmg_to_skill():
        for x in test_list:
            x.dmg = 10

    def display_text():
        renpy.say(None, "Test if the damage is 10 for real? Damage: %s Yep!" % [x.dmg for x in test_list])
        renpy.say(None, "Problem is that damage is not updated in skill_description")
        renpy.say(None, "How to update damage through class list so it can display correct value in screen?")

    test_list = [Skill()]
screen test():
    for x in test_list:
        text "%s" % x.skill_description xalign 0.500 yalign 0.500

label start:
    show screen test
    "Everything is fine skill damage is 5 now..."
    "Lets make skill damage 10!"
    $ add_dmg_to_skill()
    "Skill damage is 10 now!"
    $ display_text()
    "End"

User avatar
RicharDann
Veteran
Posts: 255
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Displaying Class Variable In Screen

#2 Post by RicharDann » Sat Mar 14, 2020 2:15 pm

Try using format() method instead:

Code: Select all

text "{}".format(x.description)
You may have to change it in the class as well.
The most important words a man can say are, “I will do better”.
The most important step is always the next one.

Nero
Veteran
Posts: 237
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Displaying Class Variable In Screen

#3 Post by Nero » Sat Mar 14, 2020 3:10 pm

I tried but sadly problem is still the same.

User avatar
gas
Miko-Class Veteran
Posts: 827
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Displaying Class Variable In Screen

#4 Post by gas » Sun Mar 15, 2020 3:53 am

When creating the class, you stated that value, and that value is. Once and forever. Changing skill_damage is not retro_active on skill_description.
So, practically speaking, skill_description is no use for.
Use interpolation directly in the interface, instead.

Code: Select all

e "Your attack is [Skill.skill_damage], and change everytime!"
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Nero
Veteran
Posts: 237
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Displaying Class Variable In Screen

#5 Post by Nero » Sun Mar 15, 2020 9:08 am

Yeah that is what I have right now... Problem is that my list contain something like [Defense(),Damage(),Damage()] (this list represents cards in hand) and each item in list has his own changeable value which can be displayed through description. And having 1 value that holds everything would be much easier to use. Anyways thanks if anyone got other advice on this let me know.

I just wanted to avoid this type of code which I have right now:

Code: Select all

                imagebutton:
                    hover LiveComposite(
                        (120, 170),
                        (0, -5), c.pic,
                        (0.066, 0.000), Text("{color=#000000}{b}{size=15}%s{/size}{/b}{/color}" % (c.mc)) if c.playable == True else Text(""),
                        (0.095, 0.590), Text("{color=#000000}{size=10}%s{/size}{/color}" % (c.desc)) if c.desc != "" else  Text(""),
                        (0.095, 0.590), Text("{color=#000000}{size=10}Deal {b}%s{/b} Damage.{/size}{/color}" % (c.dmg)) if c.dmg > 0 else  Text(""),
                        (0.095, 0.660 if c.dmg > 0 else 100), Text("{color=#000000}{size=10}Gain {b}%s{/b} Armor.{/size}{/color}" % (c.armor )) if c.armor > 0 else Text(""),
                        (0.095, 0.720 if c.dmg and c.armor > 0 else 140 if c.armor > 0 else 112), Text("{color=#000000}{size=10}Apply: %s %s{/size}{/color}" % (c.desc2, [x.duration for x in c.ailments])) if c.ailments != [] else Text(""),
                        (0.015, 0.110), Text("{color=#00ff00}{size=25}{b}+{/b}{/size}{/color}") if c.upgraded == True else  Text(""),
                        )

Post Reply

Who is online

Users browsing this forum: Google [Bot]