Point-based games and deciding tiebreakers

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.
Message
Author
Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#16 Post by Valmoer »

First part : good.

Edit : as we got over to the second page, i'll reprovide a bit of context by quoting the previous message.
My Question: explain those two lines in natural language.

Code: Select all

$ menuitems = [ ("The Number Five", 5), ("The Word 'blue'", "blue") ]
$ result = renpy.display_menu(menuitems)
Your answer
  • Let there be a function called menuitems.
  • Let the function's parameters include the key items "The Number Five," and "The Word Blue."
  • Let the values of those key items include "5" and "blue."
  • Let there be a function called result.
  • For the function result, display a menu containing the parameters of the function 'menutitems.'
Second part... yikes. You're mistaking the words functions, parameters, variables, values quite a bit.

The correct answer was :
  • Let there be a variable called menuitems.
  • Let the value of the variable menuitems be a list ( It opens with [ square brackets ] )
    • that contains a tuple ( It opens with ( parenthesis ) )
      • that contains the text string "The Number Five" and the number 5
    • and that contains another tuple
      • that contains the text string "The Word 'blue'" and the text string "blue"
  • Let there be a variable result
  • Let there the value of the variable result be
    • the result of calling of the function renpy.display_menu
      • with the parameter menuitems
Now, in practice, the renpy.display_menu() function display an on-screen menu using the value / contents of the variable 'menutitems' : the first values of the tuples as the displayed text, the second as the returned value.

The problem you had is that you put the cart before the horses : in the first line, there is absolutly no concept of function. Therefore, you can't use the words function and parameters to describe it. The variable defined on line one will indeed be used as a parameter on line two, but as long as we're on line one, 'we' can't see nor know that. See the separation of concepts ?

Do keep trying! Coding can seem hard, but it's simply a complex construct of simple parts - master the parts, and you shall master the whole.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#17 Post by zomgenius »

Oh, wow. Okay, yeah, that makes a lot of sense. o: I need to work on remembering what parts mean what, and how they work. xD But that makes a lot more sense now, I think. :D I'm going to try to put it into practice, and see what I can do! Thank you so, so much for all your help. :3
Image
Paper Stars: A Visual Novel
What do you wish for?

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#18 Post by zomgenius »

Okay, I gave it a try in Ren'Py. I ran the Script Check, and it came up with a few errors. I fixed most of them, I think, but there are parts I am just unsure about. Could you take a look? I attached it as a text file!

The main problems the script check had were with the following parts:

Code: Select all

File "game/script.rpy", line 66: end of line expected.
    if eat: $ hunger_points += 1
            ^

Code: Select all

File "game/script.rpy", line 67: expected statement.
    elif drink: $ drink_points += 1
              ^

Code: Select all

File "game/script.rpy", line 73: invalid syntax
                    'hunger': hunger_points
                            ^
I tried fiddling around with the code in Ren'Py, but I just don't see which part I'm messing up. I don't think I was able to get the new point-allocation part correct, though I gave it my best shot!
Attachments
practicing.txt
(2.5 KiB) Downloaded 86 times
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#19 Post by Valmoer »

Warning : long post incoming

Code: Select all

define e = Character('Eileen', color="#c8ffc8")

# The game starts here.
label start:
    $ drink_points = 0
    $ hunger_points = 0
    $ social_points = 0
    
    e "You've created a new Ren'Py game."
    e "Once you add a story, pictures, and music, you can release it to the world!"
    "There was a brief moment of silence as she considered what she should do next."
    
    menu:
        "Get a drink.":
                $ drink_points += 1
        "Eat nachos.":
                $ hunger_points += 1
        "Call Susie.":
                $ social_points += 1
        "Do nothing.":
                jump next

label next:
   e "Now what should I do?"
   "She thought about her options again."
   menu:
        "Get a soda.":
                $ drink_points += 1
        "Eat fruit.":
                $ hunger_points += 1
        "Call Jake.":
                $ social_points += 1
        "Do nothing.":
                jump end
                
So far so good. (The script check did told you so, but it is also almost completely correct on a code design standpoint).

I'll just comment on the fourth menu choice (for both of your menus) : you put a jump statement when you "Do nothing". Now, I understand why you did it : it is mandatory to put at least one renpy statement after a ':'-ended statement (here a menu choice).

But it is also bad practice, structurally speaking, to put a jump in one of your choices when not any of the other does, and it is bad practice of semantic design to put a action after the choice "doing nothing".

Yet, fear not! Here is your savior, the pass statement, which allow you to tell renpy to... well, not do anything. Seems useless, huh ? But pretty useful here. Just tell him to do nothing when the user chose to do just that. :)
--------------

Code: Select all

python:
    points = {
        'drink': drink_points,
        'hunger': hunger_points,
        'social': social_points,
    }
Okay, the initialisation of the dictionary is cool.
--------------

Code: Select all

    highest_points = max(points.values())
    people_with_highest_points = []
    for person, person_points in points.iteritems():
        if person_points == highest_points:
            people_with_highest_points.append(person)
You cut-and-paste. You cut-and-paste. You cut-and-paste. YOU CUT-AND-PASTE. DON'T DO IT. FOREVER.
Cut-and-paste is the bane of good coding. Cut-and-paste is the enemy of all mankind. Cut-and-paste will come at night and eat your babies! Seriously, cut-and-paste is evil. As a proof, look at Discord : he's a cut-and-paste monster, and he's evil.
Jokes aside, always try to re-code yourself everything you code, even if you end up re-coding it letter for letter - it has several advantages:
  1. You're in control of everything in your code - and, reciprocally, you're responsible for everything in your code. You feel a greater responsability to have your code proper and clean, while one is unconciously much more cavalier towards the lines you pilfered from someone else.
  2. Re-writing a block allows you - in fact, forces you - to think about the sense and meaning of what you're coding.
    It is just as if you were spelling out a word, or translating a foreign language sentence.
  3. It allows you to combine what you have with what you need to produce what you want.
    If you go the cut and paste route, you just modify what you have.
  4. In fact, when you cut paste, you tend to overlook mistakes - or, if you modify part of it, you miss other references to the cut&pasted passage's elements.
Cut-and-paste might seem like it makes you gain time at first, but in the long run it is a net loss of time to fix the eventual mistakes.

Valmoer goes down from his soapbox.

Now, I don't say that you shouldn't have used this block of code - actually, it is a good thing you used it - but remember what I said about the fact that the name of variables was of no importance to the computer, but of vital importance to the coder, so he could understand what he codes, what the variables he uses are used for ? Look, here, you have
  • highest_points : it is the maximum value of a collection of points value : it is well-named
  • people_with_highest_points : it is a list that is about to store the names (keys, actually) of the points dictionary items that has the highest total points. But what are these dictonary items ? What is their semantical sense ? Their lexical field ? "drink", "hunger", "social" - those aren't people, and thus people_with_highest_points is ill-named. (I'd suggest categories_with_highest_points (or highest_points_categories - it's the same thing, really.)) You can name your variables as you wish, so name them with something meaningful.
  • The same reason makes person and person_points ill-named
--------------

Code: Select all

if len(people_with_highest_points) > 1:
      $ menuitems = [ ("I'll take a sandwich", "eat"), ("I'll rather have a glass of water", "drink") ]
      $ result = renpy.display_menu(menuitems)
      if eat: $ hunger_points += 1
      elif drink: $ drink_points += 1
      jump goodbye
Okay, this is where it's begining to go down the drain.
First things first - why is renpy shouting at you ?

Code: Select all

      if eat: $ hunger_points += 1
      elif drink: $ drink_points += 1
It is because, in renpy (and in python) one line = one statement. But here, you have two statements for each line:
  • the if / elif condition :
  • and a python statement, which here of the form $ variable operator value
So, the correct way to format your code - with the right indentation

Code: Select all

   if eat:
      $ hunger_points += 1
   elif drink:
      $ drink_points += 1
which doesn't matter, because the code is wrong anyway. :lol: :roll:
So let's start again your code, just modified to be syntaxically correct:

Code: Select all

if len(people_with_highest_points) > 1:
      $ menuitems = [ ("I'll take a sandwich", "eat"), ("I'll rather have a glass of water", "drink") ]
      $ result = renpy.display_menu(menuitems)
      if eat:
            $ hunger_points += 1
      elif drink:
            $ drink_points += 1
      jump goodbye
First, cut-and-paste strike again : for the first three lines, you took the code we three made together, and just let it as is. Now let me ask you : would that code play its intended role if 'social' was one of the tied values ? No, of course not.
See the end of my post for a relevant homework assignation.

Next, we have this:

Code: Select all

      if eat:
            $ hunger_points += 1
      elif drink:
            $ drink_points += 1
which is thrice wrong
  1. You're confusing eat, the variable, and "eat", which is a text string, i.e. a litteral value. While eat might be affected any value (42, 0, "zoo", 3299902.28, "J3rezjkl _9oi", ["blargh", 76, 8.3]... and so on), the litteral will never have any other value than itself : here, the value "eat".
    What you were doing here is asking renpy if eat was True. A variable that is True is a variable that isn't False, 0, or an empty list []. That means that any variable that has been initialized to a value different from those would be True. Here, however, as you never initialized eat, it would have crashed as soon as you'd arrived there.
  2. So what you do want to do here is rather compare the returned value of the renpy.display_menu(...) function to the value you know it might have. It would look like that

    Code: Select all

          if result == "eat":
                $ hunger_points += 1
          elif result == "drink":
                $ drink_points += 1
  3. But what you MUST realize is that these preceding four lines are utterly useless. You try to add one point to your category_points, but you don't have to! The tie has already been broken! It has been the moment the user chose a element in the menu. And this choice has been materialised by the result variable. So if you want to know which was the winning category, just "ask" the result variable (we could have called it decision...). This fact, by the way, makes obsolete half of your following code. I will, however, continue to demolish it for educational reasons. :lol:

Code: Select all

else:
    python:
        points = {
                'drink': drink_points
                'hunger': hunger_points
                'social': social_points
        }
        highest_points = max(points.values())
        people_with_highest_points = []
        for person, person_points in points.iteritems():
            if person_points == highest_points:
                people_with_highest_points.append(person)
    
    jump goodbye
Starting from here, things stop making sense. :shock: :evil:
I kind of guess what you were trying to do - that is, you put modified drink/hunger in the above if and wanted to have anew a list with the item with the maximum values, but
  1. why the Hell would you put it in the else statement of the if len(people_with_highest_points)>1 statement: remember, that if len(...) > 1, it means there is more than one 'maximum'. Conversely, if you go to the else statement, it meant that len(people_with_highest_points)>1 was false, that is that there was one or less element in people_with_highest_points i.e, that there is no tie. So no putting tiebreaking code in this else statement.
  2. what you should have put in else : as I said , if you been up to else, it means there is no tie, and that there is only one element in people_with_highest_points. What do we do ? We access it with people_with_highest_points[0] (in a general manner, you access the nth element of a list with listname[n-1]) And, now, look carefully, cause it's a simple yet wicked trick. We'll stock this value in a variable named... result.

    Code: Select all

    else:
         $ result = people_with_highest_points[0]
    That means that result will contain the name of the highest value. And this, whatever path was taken (either the if or the else). Wicked, isn't it ? (Do make sure however, that the menu-returned results are the same that the dictionary's keys names, for this to work)
  3. Regardless of the code's inherent worth, you should never have twice the same code in your program. If you do, you need to define a function. But we'll see that later.
  4. Again, as with your menu choice, the jump statement was unecessary.

Code: Select all

label goodbye:    
    if hunger_points > max(drink_points, social_points):
       e "Man, I am never eating another bite!"
    if drink_points > max(hunger_points, social_points):
       e "I sure was thirsty."
    if social_points > max(hunger_points, social_points):
       e "I love talkting with friends."
What are you doing here ? You're checking which is the maximum? YOU ALREADY HAVE! And, you see, Cut-and-paste is bad (I know it is c&p, I've seen that code wheeze around in a few topics of the forum). You already have your result, so no need to make a calculation anew.
--------------
Wew. So let's see what your code gives, Valmoer-styled:

Code: Select all

define e = Character('Eileen', color="#c8ffc8")

# The game starts here.
label start:
    $ drink_points = 0
    $ hunger_points = 0
    $ social_points = 0
    
    e "You've created a new Ren'Py game."
    e "Once you add a story, pictures, and music, you can release it to the world!"
    "There was a brief moment of silence as she considered what she should do next."
    
    menu:
        "Get a drink.":
            $ drink_points += 1
        "Eat nachos.":
            $ hunger_points += 1
        "Call Susie.":
            $ social_points += 1
        "Do nothing.":
            pass

                
label next:
   e "Now what should I do?"
   "She thought about her options again."
  
   menu:
        "Get a soda.":
                $ drink_points += 1
        "Eat fruit.":
                $ hunger_points += 1
        "Call Jake.":
                $ social_points += 1
        "Do nothing.":
                pass
                
label end:
    python:
        points = {
            'drink': drink_points,
            'hunger': hunger_points,
            'social': social_points,
          
        }
        highest_points = max(points.values())
        highest_points_categories = []
        for category, category_points in points.iteritems():
            if category_points == highest_points:
                highest_points_categories.append(category)
            
    if len(highest_points_categories) > 1:
         $ menuitems = # This is your homework
         $ result = renpy.display_menu(menuitems) 
    else:
         $ result = people_with_highest_points[0]

label goodbye:    
    if result == "eat":
       e "Man, I am never eating another bite!"
    if result == "drink":
       e "I sure was thirsty."
    if result == "social":
       e "I love talkting with friends."

    e "I guess that's all, then!"
                
    return
See the

Code: Select all

    if len(highest_points_categories) > 1:
          $ menuitems = # This is your homework
          $ result = renpy.display_menu(menuitems) 
Here is your third homework assignation (this one is a bit tricky) : you have a list, highest_points_categories, that contains the names of the categories with the highest point total. You don't know which are the names inside.
Find a way to define correctly the menuitems variable, so that the when you pass menuitems as parameter to renpy.display_menu(...) function, a menu with the tied values, and only those - will appear.
Do read carfully the renpy.display_menu() function definition, so that you know what is the "shape" of the parameters that the function expects.
This function might help you.


Now, don't be disheartened - mistakes are normal, and I can honestly tell you that you are doing well (for an English major :twisted: :mrgreen: :lol:). Again, don't hesitate if you have any question :wink:

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#20 Post by zomgenius »

Eep!! Yeah, I'm definitely guilty of cut-and-paste, or at least trying to make what I have as similar as possible to something else. I need to stop that, heheh. Though Discord is awesome, even if he is an evil, terrible, cut-and-paste monster. D: But I can understand all that. I'll try to keep doing everything from scratch; like you said, it'll help a lot more in the long run for sure.

I completely forgot about the pass option! That's something I'll have to remember in the future, for sure.


Code: Select all

    if len(highest_points_categories) > 1:
          $ menuitems = # This is your homework
          $ result = renpy.display_menu(menuitems) 
Okay!! I think I have an idea of what I need to do. I'm going to try writing it out before actually doing it, to see if I really understand it or not.

For the value, I need to put a list into the variable menuitems, and it should open with brackets. Inside, there needs to be some sort of code that will allow all tied items to be shown, and only those items, or none if there is no tie. Inside the brackets is where I start to lose momentum. I was looking over the function you linked me to - the zip one. I am pretty sure that it would work to bring up the items we need, but I don't quite know how to write it out. I was thinking something like this, though I am also just guessing a tiny bit.

Code: Select all

    if len(highest_points_categories) > 1:
          $ menuitems = [zip(highest_points_categories)]
          $ result = renpy.display_menu(menuitems) 
If that wouldn't work, I was also thinking of listing the items, but using zip for them. The only problem I see with that is the fact that you would have to have every single item in there, just in case. And we don't want every single item to be shown - only the ones that are in a tie.

Am I getting somewhere with this? o:

I'm glad to hear that I'm at least catching on a bit! xD This is a lot more difficult than I expected; I've never tried learning a programming language like this before. I've only ever dabbled in web design, at the most. :P Thank you for your help, you're a great teacher so far!! :D (And hey, English majors are awesome, okay? :3)

EDIT:
Okay, I just realized that if I left the zip part there and didn't include anything, it wouldn't show anything for the text string on the menu choices, etc. So instead, I need to have something that allows me to show the desired text string, along with the desired values. Hold on, I'll come back and edit this again once i think I've figured it out a bit more.

... Yeah, okay, I've got nothing. :c I can't think of a way to get the text strings into the values properly. You said this a couple of posts ago:
Now, in practice, the renpy.display_menu() function display an on-screen menu using the value / contents of the variable 'menutitems' : the first values of the tuples as the displayed text, the second as the returned value.
So I know that in the menuitems list, I have to have tuples with the desired text as the first value, and the actual choice as the second value. But the tricky part is deciding how to get that to show correctly when you have different items, depending on your situation! I thought I might have had it figured out using the zip part - by using that, we could draw out the ones that had the highest points. Would the text / choice values go inside the zip part somehow? zip(["Get a sandwich", "eat"], ["Get a glass of water", "drink"], ["Call someone else", "social"]) or something similar? Even if I did that, I'd have to list every single one, right? Argh. I can feel the wheels trying to turn, but I'm just not going anywhere.
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#21 Post by Valmoer »

For the time being, forget the fancy texts (The "Get a..." ones), and try to simply set the names ('hunger', 'drink' & 'social') as both the displayed text and as the return values.

As a hint, the expected format for display_menu()'s parameter is = [ ( title1 , returnvalue1 ) , ( title2 , returnvalue2 ) , ... ] : a list of 2-tuples.

And finally, do read very carfully the example the python tutorial gives for the zip function - it will tell you precisely how it works.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#22 Post by zomgenius »

Okay, forget the fancy names. Got it. -casually throws all the fancy names out a window-
zip([iterable, ...])
This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

Code: Select all

   if len(highest_points_categories) > 1:
          $ menuitems = [(hunger, hunger), (drink, drink), (social, social)]
          $ result = renpy.display_menu(menuitems)
This would display all three choices, I think. And that is not what we want. So instead, we want to use the zip function to return the tied choices only. Is it just as simple as having the zip function call the tuples I just listed in menuitems? I feel like I'm over-thinking it all. Okay, I'm going to try to start from square one again.

We need to make a list of menuitems that will show when there is a tie.
Only the tied items should show when display_menu is used.
Because of that, we cannot simply list the tuples as they are in menuitems; this would show all of them, every time.
Instead, we need to use something that will call only the highest point categories out.
When these values are called out, they will still need text to be displayed as well as the actual value that will be chosen.
So in this case, do we use zip to call out certain values at certain times?

I think I need another hint; I seem to be going nowhere. :(
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#23 Post by Valmoer »

Code: Select all

$ menuitems = [[(hunger, hunger), (drink, drink), (social, social)]
Watch it, you're mixing variable names (hunger) and litteral text strings ('hunger') again.
I think I need another hint
I'm gonna put all we know side by side.
  • The pattern expected by the function is [ ( title1 , returnvalue1 ) , ( title2 , returnvalue2 ) , ... ]
  • The variable contains a list of text strings [ 'text1' , 'text2', ...]
  • The zip( )function use as arguments from 1 to an arbitrary number of lists, and gives returns the following:
    zip(list1, list2, ...) == [ (list1[0], list2[0], ...) , ( list1[1], list2[1], ... ) , ... ]
Now all that remains is putting all of this together.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#24 Post by zomgenius »

Ah, whoops. xD;; I see what I did wrong there, okay.
Let's try this again!

Based off what you said, I think we need to zip the two sections together - the pattern expected by the function, and the list of text strings. So in order to get the zip to call forth the right lists, we need to have the list of text strings, and we need to have the list that includes the highest points categories and their values. Does that sound right so far?

(I'm hoping that if I keep working at this, it'll just click at some point, and I will understand it. xD)

Putting it together is the difficult part for me. I think I understand what needs to go into everything when I think about it; writing it out is just the part that keeps giving me trouble. Maybe if I ask a few questions first, I can try writing it out.

First, do I need to list the pattern expected by the function, with [('hunger', hunger), ...] etc? And if I do, should I then jump down a line, indent it properly, and continue with the zip function? Or can the zip function be included as a part of the menuitems? And if it is included as part of the menuitems, should it be before or after the pattern expected, if that is supposed to be there at all? And when using the zip function, do all the different parts you are using to zip together need to be in the same line, or should they be defined earlier?

I just can't seem to figure these things out. :/
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#25 Post by Valmoer »

You're overthinking it. Really.
do I need to list the pattern expected by the function, with [('hunger', hunger), ...]
No : i just writed that pattern so that you would know what the function expects as a parameter.
Or can the zip function be included as a part of the menuitems
That's more like it : the zip function return a value (that value is dependant upon the parameters you gave it), and you can then assign that value to menuitems.
And when using the zip function, do all the different parts you are using to zip together need to be in the same line, or should they be defined earlier?
You call a function by writing functionname(parameter1, parameter2,...). That the parameter are either variables defined before or literals is irrelevant. Remember - it is an addition of parts. Focus on what the function does - on what the function expects - on what the function produce. Understand all three, and you've understood the function as a whole.

Here :
  • you need to produce a list of 2-element-tuples
  • zip returns a list of n-item tuples, where n is the number of parameter lists.
  • it means you must give two lists as parameters to zip()
  • you want the first item of the tuples to be the displayed text
  • it means your first list must contain the displayed text list.
  • you want the second item of the tuples to be the returned value
  • it means your second list must contain the returned value list.
  • we decided that the displayed text and the return values would be the same
  • it means that the list that will be passed to zip() as a parameter twice (replacing both parameter1 & parameter2 in my above example) will be ___________ ?
Hold on :) - I know it feels like navigating a fog, but once you get how function calls works, it will get a lot easier.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#26 Post by zomgenius »

Ah, okay! That helps clear some stuff up.

Code: Select all

   if len(highest_points_categories) > 1:
          $ menuitems = zip(['hunger', 'drink', 'social'], ['hunger', 'drink', 'social'])
          $ result = renpy.display_menu(menuitems)
I am going to cross my fingers and hope I got it this time! I feel like things suddenly got a lot more clear, so I'm really hoping I'm onto something here. :3
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#27 Post by Valmoer »

Yep, nearly there! You got the concept behind the zip function right this time.

What you coded there would get :
The menu obtained.
The menu obtained.
screenshot0001.png (8.67 KiB) Viewed 1887 times
everytime there is a tie. Which isn't what we want - we want only the tied values, the ones with the highest_points value. And, as a matter of fact, we have already generated a list that contain the names of those tied, highest-valued categories.

And the name of that list is.... ?

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#28 Post by zomgenius »

Oh! The highest_points_categories list!

So then, instead of the values, we would input the list name!

Code: Select all

   if len(highest_points_categories) > 1:
          $ menuitems = zip(['hunger', 'drink', 'social'], [highest_points_categories])
          $ result = renpy.display_menu(menuitems)
This way, it displays the text for the items, but will only take the tied values, right?
But what stops it from assigning 'hunger' as the text value to 'drink' by mistake?
Image
Paper Stars: A Visual Novel
What do you wish for?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: Point-based games and deciding tiebreakers

#29 Post by Valmoer »

Yeeee - no.

Code: Select all

   if len(highest_points_categories) > 1:
          $ menuitems = zip(['hunger', 'drink', 'social'], [highest_points_categories])
          $ result = renpy.display_menu(menuitems)
  1. highest_points_categories is already a list - no need to surround it with brackets.
  2. But what stops it from assigning 'hunger' as the text value to 'drink' by mistake?
    [sarcasm]Gee, what list do I have that is ordered in the same way than highest_points_categories and have the same values inside ? [/sarcasm]
Hint:
ITSELF!
Do you test your code with renpy ? If you don't, do it : it would help you a lot.
And sorry for the sarcasm - but I did though you would get it right this time.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Point-based games and deciding tiebreakers

#30 Post by zomgenius »

Oh. Wow. I feel kind of dumb for not realizing that. D: Yeah, you're right; it'd just be the same thing twice, wouldn't it?

Code: Select all

   if len(highest_points_categories) > 1:
          $ menuitems = zip(highest_points_categories, highest_points_categories)
          $ result = renpy.display_menu(menuitems)
So that way, it'll show the correct values for both, depending on what is the highest or tied.
Image
Paper Stars: A Visual Novel
What do you wish for?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], piinkpuddiin