Quick question about point-based systems (SOLVED)

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
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Quick question about point-based systems (SOLVED)

#1 Post by HeavenlyJoker » Tue Jun 18, 2013 5:56 pm

I've read the documentation about point-based systems, but I have a question concerning how to make something easier. I have ten stats I'm dealing with, and I have a moment in the game where I need to be able to tell Ren'Py to take the top two of these stats and jump to a certain label talking about them together. For example, what I was planning to do was to say something along the lines of this:

Code: Select all

    if stat1_points and stat2_points > stat3_points and stat4_points...:
        jump label discussstat1and2
    if stat1_points and stat3_points > stat2_points and stat4_points...:
        jump label discussstat1and3
    ...
the ellipses just representing the continuation of the line; I really didn't want to write all of it out for an example. But, since I have ten stats to deal with, it seems like this is going to be pretty cumbersome. It's not that I mind doing it, but I really would like to simplify it if I can. If anyone has any suggestions, please let me know! :3
Last edited by HeavenlyJoker on Sun Jul 07, 2013 3:18 pm, edited 1 time in total.

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Quick question about point-based systems

#2 Post by apricotorange » Wed Jun 19, 2013 12:04 am

Something like this?

Code: Select all

    $ stat_list = [stat1_points, stat2_points, stat3_points, ...]
    jump expression ("disscussstat" + "and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]]))
Granted, it probably wasn't a good idea to write that in one line, but it was fun. :)

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Quick question about point-based systems

#3 Post by HeavenlyJoker » Wed Jun 19, 2013 4:07 am

Wow that is a large complex chunk of code you've got there xDD If it's not too much trouble, would you mind breaking it down for me so I understand exactly what it is I'm typing in and telling the program to do? I've never seen anything quite like this before :3

And thank you so much for your help!!

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Quick question about point-based systems

#4 Post by xela » Wed Jun 19, 2013 8:47 am

Code: Select all

    $ stat_list = [stat1_points, stat2_points, stat3_points, ...]
    jump expression ("disscussstat" + "and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]]))
Just google:

python + string
python + join() string method
python + tuple
python + sorted()
python + zip()
python + for loop
python + range()
python + list + slicing

Otherwise it would take to long to explain...
Like what we're doing? Support us at:
Image

User avatar
spiral
Regular
Posts: 41
Joined: Mon Mar 04, 2013 5:48 am
Location: Australia
Contact:

Re: Quick question about point-based systems

#5 Post by spiral » Fri Jun 21, 2013 10:15 am

I'll have a go at untangling it as a challenge to myself...

Code: Select all

$ stat_list = [stat1_points, stat2_points, stat3_points, ...]
    jump expression ("disscussstat" + "and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]]))
So, we want to:
Create a list stat_list of all the stats
Calculate the top two stats statA_points and statB_points
jump to disscussstatAandB

("disscussstat" + "and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]])) is "disscussstatAandB", as shown below:

range(10)=[0,1,...9]
zip([-x for x in stat_list], range(10))=[(-stat1_points, 0), (-stat2_points, 1),(-stat3_points, 2)...]
sorted(zip([-x for x in stat_list], range(10)))[:2]=[(-statA_points, A-1), (-statB_points, B-1)]
[str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]]=["A", "B"]
"and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]])="AandB"
("disscussstat" + "and".join([str(y+1) for (x,y) in sorted(zip([-x for x in stat_list], range(10)))[:2]]))="disscussstatAandB"

Hopefully that makes it a little clearer. I would never have come up with such a concise way of writing it myself!

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Quick question about point-based systems

#6 Post by HeavenlyJoker » Fri Jul 05, 2013 6:44 pm

Thank you so much! (Sorry this is a late reply =w=) That helped to clear a lot up; I got the code working perfectly! <3

Now for a slightly more complicated version of this question: Does anyone know of a good way to do sort of the same thing but with two changes? Those being, I just need the highest stat (as opposed to the two highest) and I need it to be over a certain number, let's say 10. If the highest point value doesn't equal 10 or more, then it jumps to a 'failed' label, if that makes sense.

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Quick question about point-based systems

#7 Post by apricotorange » Fri Jul 05, 2013 9:47 pm

Do you care what the behavior is if multiple stats are tied?

A bit more readable this time:

Code: Select all

    $ (max_points, max_index) = max(zip(stat_list, range(10)))
    if max_points < 10:
        jump failed
    jump expression ("discussionstat" + max_index)

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Quick question about point-based systems

#8 Post by HeavenlyJoker » Sat Jul 06, 2013 3:58 pm

apricotorange wrote:Do you care what the behavior is if multiple stats are tied?

A bit more readable this time:

Code: Select all

    $ (max_points, max_index) = max(zip(stat_list, range(10)))
    if max_points < 10:
        jump failed
    jump expression ("discussionstat" + max_index)
Thank you so much! I definitely understand more this time around! I don't really care if the stats are tied; does the tie just go in order of the first label?

I do seem to get an error though, and I'm not sure how to fix it; it says "TypeError: cannot concatenate 'str' and 'int' objects". Any thoughts? :3

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Quick question about point-based systems

#9 Post by xela » Sat Jul 06, 2013 4:58 pm

HeavenlyJoker wrote:
apricotorange wrote:Do you care what the behavior is if multiple stats are tied?

A bit more readable this time:

Code: Select all

    $ (max_points, max_index) = max(zip(stat_list, range(10)))
    if max_points < 10:
        jump failed
    jump expression ("discussionstat" + max_index)
Thank you so much! I definitely understand more this time around! I don't really care if the stats are tied; does the tie just go in order of the first label?

I do seem to get an error though, and I'm not sure how to fix it; it says "TypeError: cannot concatenate 'str' and 'int' objects". Any thoughts? :3

Try the same code but:

Code: Select all

jump expression ("discussionstat" + str(max_index))
Like what we're doing? Support us at:
Image

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Quick question about point-based systems

#10 Post by HeavenlyJoker » Sat Jul 06, 2013 5:19 pm

xela wrote:

Try the same code but:

Code: Select all

jump expression ("discussionstat" + str(max_index))
Now it's showing "ScriptError: could not find label 'discissionstat0'.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Quick question about point-based systems

#11 Post by xela » Sat Jul 06, 2013 7:36 pm

HeavenlyJoker wrote:
xela wrote:

Try the same code but:

Code: Select all

jump expression ("discussionstat" + str(max_index))
Now it's showing "ScriptError: could not find label 'discissionstat0'.
?

You're doing something wrong, those are not even the same words (discussion, discission). Latter is not even a word btw.

That code will return the first string ("discussionstat") and the corresponding index. If your code still depends on 10 stats, starting with stat1 and you want to jump to discussionstat1 label when 0 index is highest, you need to adjust the code to:

Code: Select all

    $ (max_points, max_index) = max(zip(stat_list, range(1, 11)))
    if max_points < 10:
        jump failed
    jump expression ("discussionstat" + str(max_index))
or

Code: Select all

    $ (max_points, max_index) = max(zip(stat_list, range(10)))
    if max_points < 10:
        jump failed
    jump expression ("discussionstat" + str(max_index+1))
Like what we're doing? Support us at:
Image

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Quick question about point-based systems

#12 Post by HeavenlyJoker » Sun Jul 07, 2013 3:18 pm

@ xela: That was just a typo.

Anyway, I messed around with the code a bit more and got it to work. I'm not exactly sure how I fixed it, but if anyone else sees this thread and has the same problem I had, you can feel free to PM me and maybe I can help you? Thanks to everyone who helped me out!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]