Problem with variables based on user input

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
realaniram
Regular
Posts: 33
Joined: Sun Sep 18, 2011 1:36 pm
Projects: Shaeyu jun Ikkshaelun
Contact:

Problem with variables based on user input

#1 Post by realaniram »

So, in my game I'm trying to make a sort of 'morality' system, based mainly off of lying and manners. So, in menu choices I'll have the 'good' option, a neutral option, and the 'bad' option, with +1 in that field if you choose it. However, it seems that even when you don't choose the option the points still get added, which is wreaking havoc on my NPC reactions. Help?

Sorry if I didn't explain that very well. Thanks in advance!
Shaeyu jun Ikkshaelun-- A work in progress.

Forever Newb

User avatar
netravelr
Miko-Class Veteran
Posts: 504
Joined: Thu Jan 28, 2010 2:31 am
Completed: Culina: Hands in the Kitchen, Culina: The Spirit of Cooking, Saving Zoey
Projects: Love at the Laundromat
Organization: Lakeview Interactive
Deviantart: netravelr
Location: USA
Contact:

Re: Problem with variables based on user input

#2 Post by netravelr »

So somewhere outside of the scope of the menu (probably at the base part of the game) you'll have a variable of some sort (morality for instance) in which you'd initialize it

Code: Select all

 morality = 0 
when you make a choice but before you jump to another section put

Code: Select all

 morality += 1 
and that will increase the amount by 1 and -= 1 will decrease it.

Or do you mean that you have a menu and you don't jump outside of the line that adds the +1?
Image
Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter
Experienced in: C/C++/C#, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."

realaniram
Regular
Posts: 33
Joined: Sun Sep 18, 2011 1:36 pm
Projects: Shaeyu jun Ikkshaelun
Contact:

Re: Problem with variables based on user input

#3 Post by realaniram »

Let's see, I actually have two variables, 'ruffian' and 'saint'. The 'bad' option adds 1 to the ruffian value, and the 'good' option adds +1 to the saint value. But, would using a count like yours where they're both one and the same be better..? It certainly sounds simpler.

Here's my code for one of the menus:

Code: Select all

    menu:
        "Destiny?  I don't believe in that crap.":
            f "I don't believe in destiny.  I can make my own path, old man."
            $ ruffian += 1
            a "You don't have a choice, young woman.  You must do this."
            
        "Destiny?  Who is he to tell me my destiny?":
            f "How would {i}you{/i} know what my destiny is?"
            a "Always the skeptic, I see."
            
        "I must follow destiny.":
            f "It's my destiny?  Then I suppose I should do it."
            $ saint += 1
            a "I'm glad you see the importance of this."
And I do have the variables declared with the starting value of 0 at the beginning too.
Shaeyu jun Ikkshaelun-- A work in progress.

Forever Newb

User avatar
netravelr
Miko-Class Veteran
Posts: 504
Joined: Thu Jan 28, 2010 2:31 am
Completed: Culina: Hands in the Kitchen, Culina: The Spirit of Cooking, Saving Zoey
Projects: Love at the Laundromat
Organization: Lakeview Interactive
Deviantart: netravelr
Location: USA
Contact:

Re: Problem with variables based on user input

#4 Post by netravelr »

Yeah if you don't initialize the value then it'll be whatever piece of memory was there in the first place which just happened to be 1 in your case. It's always a good idea to initialize stuff before you use it. Hope I helped!
Image
Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter
Experienced in: C/C++/C#, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."

Post Reply

Who is online

Users browsing this forum: Google [Bot], Imperf3kt, voluorem