Point Based Game Help!

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
Juliehovonatch
Newbie
Posts: 3
Joined: Mon Jul 18, 2011 12:47 am
Contact:

Point Based Game Help!

#1 Post by Juliehovonatch »

I am trying to make a point based game, but every time I try and have the player gain or lose points I get an error saying something like NameError: name 'Dren_points' is not defined. I did the coding at the very beginning like the guide said

Code: Select all

label start:
    $ Dren_points = 0
    $ Will_points = 0
    $ Ellie_points = 0
    $ Liam_points = 0
and then when I had the player gain points I put

Code: Select all

label incorrect_choice:
    $ Dren_points -= 1
What am I doing wrong?

0ion9
Regular
Posts: 79
Joined: Thu Jun 16, 2011 9:17 am
Contact:

Re: Point Based Game Help!

#2 Post by 0ion9 »

You need to make sure those variables are defined before they are used. This is not necessarily done by putting one after the other.
Anything that needs initialization should go in an init block, to ensure it executes before any part of the story code. (see http://www.renpy.org/wiki/renpy/doc/tut ... _Structure)

Juliehovonatch
Newbie
Posts: 3
Joined: Mon Jul 18, 2011 12:47 am
Contact:

Re: Point Based Game Help!

#3 Post by Juliehovonatch »

Thank you so much! That fixed it :)

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Point Based Game Help!

#4 Post by Showsni »

Except, if you save the game and then restart it'll init them back to 0, which presumably isn't what you want. Tell me, when you were getting the errors, were you testing from a saved game? If so, then it makes sense you'd get errors, because the save won't go through the start label and initialise them, if you added the $ Dren_points = 0 etc. after making the save. Initialising after the start label is fine, but you need to test all over from the beginning rather than using a prior save if you do so.

marvelmx
Newbie
Posts: 20
Joined: Wed Jul 20, 2011 10:26 am
Contact:

Ending based in points

#5 Post by marvelmx »

I think this post can go here, anyways I have a point system and have reached the ending, but I get this error:

ERROR:

While running game code:
File "game/script.rpy", line 279, in script
if puntos_buenos > max (puntos_malos):
File "game/script.rpy", line 279, in python
if puntos_buenos > max (puntos_malos):
TypeError: 'int' object is not iterable

The game runs well until it reaches the if after the "more random text" in label choice6_done. Im trying to have the good ending if the chracter has a mayority of good points, bad ending if the chacter has 4 or less bad points (in which case the maximun of good points is 2 anyways so bad points are still mayority) and the worst ending only if player got 5 bad points, my code is this:

CODE:

label choice6_done:
e "random text"
"more random text"

if puntos_buenos > max (puntos_malos):
jump finalbueno
elif puntos_malos > max(puntos_buenos) <= 4:
jump finalmalo
elif puntos_malos == 5:
jump finalpeor

label finalbueno:
"more random text"
jump gameover

label finalmalo:
"more random text"
jump gameover

label gameover:
"more random text"

return

0ion9
Regular
Posts: 79
Joined: Thu Jun 16, 2011 9:17 am
Contact:

Re: Point Based Game Help!

#6 Post by 0ion9 »

max() is a function that accepts a *sequence* and returns the maximum value. it doesn't accept an integer.

marvelmx
Newbie
Posts: 20
Joined: Wed Jul 20, 2011 10:26 am
Contact:

Re: Point Based Game Help!

#7 Post by marvelmx »

Thanks, then I should take away the max and leave it like that or what do I use for an integer to make this work?

0ion9
Regular
Posts: 79
Joined: Thu Jun 16, 2011 9:17 am
Contact:

Re: Point Based Game Help!

#8 Post by 0ion9 »

That's right.

marvelmx
Newbie
Posts: 20
Joined: Wed Jul 20, 2011 10:26 am
Contact:

Re: Point Based Game Help!

#9 Post by marvelmx »

wow, thanks I just removed the max and it worked just fine, now I just have the problem of being unable to get the worst ending to work, earlier in the game there was a jump directly to the worst ending, so the label of the worst ending is before the menu for the last otion and the other endings, does that matter or should I move the worst ending to the end of the script were the other endings are?

now I have this:

if puntos_buenos > (puntos_malos):
jump finalbueno
elif puntos_malos > (puntos_buenos) <= 4:
jump finalmalo
elif puntos_malos >= 5:
jump finalpeor

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Point Based Game Help!

#10 Post by Showsni »

It won't matter where in your script the label is, no. You can use and when checking, like so:

Code: Select all

if puntos_buenos > puntos_malos:
    jump finalbueno 
elif puntos_malos > puntos_buenos and puntos_malos <= 4:
    jump finalmalo
elif puntos_malos >= 5:
    jump finalpeor
Of course, you're missing the case where bad points and good points are equal...

marvelmx
Newbie
Posts: 20
Joined: Wed Jul 20, 2011 10:26 am
Contact:

Re: Point Based Game Help!

#11 Post by marvelmx »

You´re right, since there are only 5 points in the game except for the last menu I hadn´t put a tie option but I already did, .

I doubled checked my code and all seemed fine , the game runs fine and normally and you can get the other endings no problem or even the worst ending by the direct option earlier on the game, the problem was solded, with an "and" , this one to be more specific

elif puntos_malos > puntos_buenos and puntos_malos <= 4:
jump finalmalo

Thanks again, I hope this helps other people too :) now I just need to figure where to change the "are you sure you want to quit" message to personalize it LOL

Post Reply

Who is online

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