Self-Balancing Stats Method isn't working :(

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
8bitRainbow
Newbie
Posts: 19
Joined: Tue Mar 29, 2016 9:21 pm
Contact:

Self-Balancing Stats Method isn't working :(

#1 Post by 8bitRainbow »

Ok I hope someone can help me because I feel like I'm pretty close to making this work and there's just something obvious I'm missing. I've been trying to code a self-balancing stat system like the kind used in 80 Days where the farther along you get in the story and the more choices you make (ie. stats you rack up), the less impact they have.

Each stat has two variables that only ever increase (strength is strength.up and strength.down, use the average to determine which has happened most of the time)... and I think the math is right but when I do a test run, no matter how often I increase "strength.down" the checking system (in this case strength.high) still returns as true. Please let me know what I'm doing wrong! I'm also open to hearing about different/better self-balancing methods if you've come up with one that works great for you.

Code: Select all

    class Stat(renpy.store.object):
        def __init__(self, average=0, up=1, down=1):
            self.average=average
            self.up=up
            self.down=down
            
        
        
        #stat adding and subtracting system
        def rise(self):
            self.up += 1
            
        def drop(self):
            self.down += 1
            
            
        #stat checking system
        def high(self):
            self.average = (self.up / (self.up + self.down))
            if self.average > .9:
                return True
            else:
                return False
        
        def more(self):
            self.average = (self.up / (self.up + self.down))
            if self.average > .7:
                return True
            else:
                return False
                
        def less(self):
            self.average = (self.up / (self.up + self.down))
            if self.average > .3:
                return True
            else:
                return False
        
        def low(self):
            self.average = (self.up / (self.up + self.down))
            if self.average > .1:
                return True
            else:
                return False

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

Re: Self-Balancing Stats Method isn't working :(

#2 Post by RicharDann »

I think it's because the result of this line:

Code: Select all

self.average = (self.up / (self.up + self.down))
Is being returned as an interger, instead of as 0.x float.

So maybe change self.up and self.down, into floats (e.g. 1.0) so the division result is more accurate.
Last edited by RicharDann on Mon Nov 13, 2017 12:29 pm, edited 1 time in total.
The most important step is always the next one.

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: Self-Balancing Stats Method isn't working :(

#3 Post by xavimat »

As RicharDann says, your code is working only with integers, and you need floats.
For example, you can simple change the first line of __init__: (only adding points to the numbers and it's done, they are floats)

Code: Select all

def __init__(self, average=0, up=1., down=1.):
But there is also another problem. In your definition of "low" the condition is ">.1". I don't get it. What if the result is 0.05? Is it not "low"? (lower, in fact).
Also, you are not defining intervals, so, if average is .95, then all functions will return True. (.95>.9) (.95>.7) (.95>.3) (.95>.1) All of them are True.
You could define intervals:

Code: Select all

average > .9
.9 >= average > .7
.7 >= average > .3
.3 >= average
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)

User avatar
8bitRainbow
Newbie
Posts: 19
Joined: Tue Mar 29, 2016 9:21 pm
Contact:

Re: Self-Balancing Stats Method isn't working :(

#4 Post by 8bitRainbow »

Oh man, I knew it was gonna be something simple like that that I overlooked. Thanks guys!

Post Reply

Who is online

Users browsing this forum: Google [Bot]