Page 1 of 1
Coding Help for a Sim with Multiple Storylines
Posted: Thu Mar 17, 2016 1:08 pm
by WizzyGameMaster
Alright, so I'm working on a dating sim that currently has 10 romanceable options. The game uses a points system and I want to code it so that at the end of the prologue, it'll jump to the guy with the most points. Sort of like how does in Katawa Shoujo: you get to the festival and if the character's points are high enough, you jump to that storyline.
But there's also certain conditions that limit the routes. Let's just call them 1, 2, and 3 to keep it simple. We'll just call the guys A, B, C, and so on
Condition 1 - A, B, C
Condition 2 - D, E, F
Condition 3 - G, H, J, K
What I want to know is, how would I write the code for that?
Also for another project that is closely related to this, how would I code the same thing without the Conditions limiting it?
Like I have A, B, C, D, E, and F and I want it to automatically jump to the route with the highest points within that group.
I've tried looking around, but because of my number of routes, nothing that I've been able to find has been usable. They all only show two or three routes in a way where adding even one more would be too messy to be functional or have the player just click the character they want which sort of defeats the whole purpose of the point system.
Can anyone help me out here? Even just an example code would be helpful
Re: Coding Help for a Sim with Multiple Storylines
Posted: Thu Mar 17, 2016 1:21 pm
by xela
I don't understand why this is different from having just the two choices:
Code: Select all
menu:
"A" if condition_1:
"B" if condition_1:
...
"K" if condition_3:
For the second part, you need a binding, like a dictionary:
when you want to add points to one of the stories, you do:
When you want to pick the story with the highest score, you get the highest value and jump to whatever key is bound to it (or resolve the jump based of the story letter). You can read about dicts in Tutorials Point, menus in Ren'Py documentation and getting the key off the highest value from a dict on stack overflow.
Re: Coding Help for a Sim with Multiple Storylines
Posted: Thu Mar 17, 2016 4:55 pm
by WizzyGameMaster
xela wrote:I don't understand why this is different from having just the two choices:
Code: Select all
menu:
"A" if condition_1:
"B" if condition_1:
...
"K" if condition_3:
For the second part, you need a binding, like a dictionary:
when you want to add points to one of the stories, you do:
When you want to pick the story with the highest score, you get the highest value and jump to whatever key is bound to it (or resolve the jump based of the story letter). You can read about dicts in Tutorials Point, menus in Ren'Py documentation and getting the key off the highest value from a dict on stack overflow.
I'm not quite understanding this. I'm still sort of a beginner with some stuff. Do you think maybe you could explain it a little clearer? (or dumb it down a bit...)
Re: Coding Help for a Sim with Multiple Storylines
Posted: Thu Mar 17, 2016 5:12 pm
by xela
Dictionaries you can use to track points. "Guys" should be keys and amount of points should be values:
http://www.tutorialspoint.com/python/py ... ionary.htm
Getting the "guy" with the highest points value is explained here:
http://stackoverflow.com/questions/6131 ... y-by-value
Jumping to a new label (starting a path/option) is explained here:
https://www.renpy.org/doc/html/label.html
If statement is explained here a little bit:
https://www.renpy.org/doc/html/quicksta ... statements
or look for the same at Tutorials Point.
===>
Forget the menu bit, I misread your post thinking that you wanted to offer the player choices but now see that you want it to be resolved automatically.
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Mar 18, 2016 1:20 pm
by WizzyGameMaster
Alright, I get the part about the dictionary and adding points. But once I get past that, I'm a bit lost. (I get the basics of jumps, labels and if statements though.)
I'm not quite getting what it is I need to do. The second link explains about sorting the values, but it seems like it matters how you do it.
Let's say I have A, B, and C. C has 12 points, A has 9 and B has 3. They are only accessible if you have Condition 1,
, and not the others. (They're set so that you can only have one of the three conditions.)
What would be the best way to code that?
If I can at least get that figured out, I think I could figure out how to code a similar thing without the conditions on my own.
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Mar 18, 2016 2:42 pm
by xela
One way would be to rebuild the dict so it only has the choices that belong to condition 1:
Code: Select all
python:
if condition1:
temp_dict = {k: d[k] for k in d if k in ["A", "B"]}
then you can get the highest value from the temp dict and you're done. Change the values in ["A", "B"] accordingly, rest of the code can remain the exact same for all of your choices. If you wish to understand what's going on, google:
python dict comprehensions.
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Mar 18, 2016 3:09 pm
by WizzyGameMaster
xela wrote:One way would be to rebuild the dict so it only has the choices that belong to condition 1:
Code: Select all
python:
if condition1:
temp_dict = {k: d[k] for k in d if k in ["A", "B"]}
then you can get the highest value from the temp dict and you're done. Change the values in ["A", "B"] accordingly, rest of the code can remain the exact same for all of your choices. If you wish to understand what's going on, google:
python dict comprehensions.
Alright, though how do I get the highest value from the temp dict and make that jump to the coordinating storyline?
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Mar 18, 2016 7:57 pm
by xela
Everything is spelled out for you in the guides, if you don't want to figure it out for yourself, you are not likely to ever complete a game with logic of any high degree complexity in it...
Code: Select all
init python:
import operator
default story_points = {"A": 1, "B": 23, "C": 11, "D": 3}
default condition_1 = False
default condition_2 = True
label start:
python:
if condition_1:
temp_dict = {k: story_points[k] for k in story_points if k in ["A", "B"]}
elif condition_2:
temp_dict = {k: story_points[k] for k in story_points if k in ["C", "D"]}
highest_score = sorted(temp_dict.items(), key=operator.itemgetter(1))[-1][0]
jump expression highest_score
label A:
"Story A"
return
label B:
"Story B"
return
label C:
"Story C"
return
label D:
"Story D"
return
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Mar 18, 2016 8:59 pm
by WizzyGameMaster
xela wrote:Everything is spelled out for you in the guides, if you don't want to figure it out for yourself, you are not likely to ever complete a game with logic of any high degree complexity in it...
Code: Select all
init python:
import operator
default story_points = {"A": 1, "B": 23, "C": 11, "D": 3}
default condition_1 = False
default condition_2 = True
label start:
python:
if condition_1:
temp_dict = {k: story_points[k] for k in story_points if k in ["A", "B"]}
elif condition_2:t
temp_dict = {k: story_points[k] for k in story_points if k in ["C", "D"]}
highest_score = sorted(temp_dict.items(), key=operator.itemgetter(1))[-1][0]
jump expression highest_score
label A:
"Story A"
return
label B:
"Story B"
return
label C:
"Story C"
return
label D:
"Story D"
return
I've got it now. Thank you for your help. My apologies if I seemed difficult. Reading about things doesn't always help me learn as easily as being given an example and trying it myself.
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Nov 18, 2016 3:02 pm
by WizzyGameMaster
So I've got this figured out, though I had a question about it.
I know that this will add to the total
and
will subtract a point, but how can I reset the value to "0"?
Like after jumping to Route "A," I want to reset only that set of points to "0" so that I can then use them as a way determining which ending the player will get. Like if you have under 5 points by a certain event, then you get the bad ending.
I've tried messing around with it, but it always gives me an error no matter what I try.
What would be the proper code to rest it to "0"? Or would it be best to use something like
instead? (I forget the exact way that kind of code goes, as I'm not looking at it right this second.)
Re: Coding Help for a Sim with Multiple Storylines
Posted: Fri Nov 18, 2016 3:09 pm
by xela