Adding all stats as a group?

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
MelMeiko
Regular
Posts: 38
Joined: Wed Apr 07, 2010 6:26 pm
Projects: Otome Eroge VN
Contact:

Adding all stats as a group?

#1 Post by MelMeiko »

I have a long list of variables that deal with the categories of "lies" "neutral" and "honesty", but they aren't specified that way (as a group).
These variables are shortened character names followed by category.

Code: Select all

# The game starts here.
label start:

    $ vilie = 2
    $ vitruth = 2
    $ vinu = 0
    $ caplie = 0
    $ capnu = 2
    $ captruth = 0
    $ justlie = 0
    $ justtruth = 0
    $ justnu = 4
    $ judtruth = 0
    $ judlie = 0
    $ judnu = 0
    $ avlie = 0
    $ avtruth = 5
    $ avnu = 0
    $ angellie = 0
    $ angeltruth = 0
    $ angelnu = 0
    $ belielie = 0
    $ belietruth = 1
    $ belienu = 0
    $ altruth = 0
    $ alnu = 0
    $ allie = 0
    $ amphilie = 0
    $ amphitruth = 2
    $ amphinu = 0
    $ sabirlie = 0
    $ sabirtruth = 0
    $ sabirnu = 0
How can I condense these to show the player how many lies, truths and neutral choices they've made? Is there a way to implement ren'py math to add up all the truth, neutral and lie numbers?

And if that can't be done or is too complicated for a beginner like me to do (lol), then how do I just show stats to the player? Like with

Code: Select all

$ amphitruth = 2
,how do I show them that with this Amphi character, they've been truthful to twice?

Thanx for looking!
Nothing and no one is absolute.

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Adding all stats as a group?

#2 Post by LordShiranai »

You could do this multiple ways to make it easier on yourself.

One easier way would be to store values in a dictionaries. For a simplified example, we have two characters: Bob and George.

We initialize them at the very start of the script.

Code: Select all

$ truth = {'Bob': 0, 'George': 0}
$ lies = {'Bob': 0, 'George': 0}
Then, for example, if you ever tell the truth to Bob, you can do the following to increment that value:

Code: Select all

$ truth['Bob'] += 1
Or we can lie to George...

Code: Select all

$ lies['George'] += 1
If you want to know the number of total times you told the truth to Bob, you can just get that value by calling truth['Bob']

Now, if you want to get the total every time you told the truth or lied to all characters, you can declare a function like this in an init block and then call it to get the total of any dictionary which has valui. (I don't think Python has a builtin function for this.)

Code: Select all

def dict_total(dict):
    x = 0
    for i in dict.values():
        x += i
    return x
Then call it in your code by using dict_total(truth) or dict_total(lies)
Don't Blame Me. I Voted for Vermin Supreme.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Adding all stats as a group?

#3 Post by Jake »

LordShiranai wrote: (I don't think Python has a builtin function for this.)
As it goes, it does; sum will add up all the items in an interable, and lists (what you get out of the dict.values() method) are iterable.

Code: Select all

>>> truth = {'Alice': 10, 'Bob': 7, 'Charlie':15}
>>> sum(truth.values())
32
Server error: user 'Jake' not found

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]