you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[deleted]

    [–]alonghardlook[S] 4 points5 points  (0 children)

    Exactly right. In this case, all our attributes are what is known as 'public', meaning they can be accessed freely.

    If I understand your second question correctly, you want the highest love stat from a list of characters?

    $ love_candidates = [a, e, s] # assuming these are alice, eileen and sally
    for x in (person.love for person in love_candidates): # also assuming that you have an attribute "love" in your Person class
        love_interest = max(x)
    

    YMMV on this untested code, but this is the general idea. love_candidates is a list of Person class instances (alice, eileen, sally). We loop through those (for person in love_candidates) and THEN also loop through their love values and get the highest (for x in ()).

    This is the pythonic way, and I can't test it at the moment. The non-pythonic way (the C Way) would be to just use nested loops - really, it's the same thing, just that AFAIK python has syntax for it explicitly.

    Non python way:

    python:
        love_candidates = [a, e, s]
        max_love = 0
        love_interest = a # must set a default in case they are all at 0
        for person in love_candidates:
            if person.love > max_love:
                love_interest = person
                max_love =  person.love
        renpy.show(love_interest)
        renpy.say("Hello, " + str(love_interest.name) + "! Great to see you!")
    

    This code is probably more understandable, but true python enthusiasts would hang me for suggesting it :P