If Statement Help (using Points)

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
Wanderer
Newbie
Posts: 11
Joined: Sun Feb 10, 2013 9:04 pm
Organization: Orange Toad Studios
Contact:

If Statement Help (using Points)

#1 Post by Wanderer »

I've been reading over various threads, but I haven't quite grasped this yet. In one of my games, subtle conversational differences will happen based on the number of points the character has in 'Aggression'. I first tried to do something where if the Aggression points were less than a value x happened, but I figured that might not be possible, and so split the points throughout Aggression, Neutral, and Passive.

I'm having trouble implementing points to menu choices and then using the if statements to decide which point actions are applied.
Alright, so the game starts out with the points all being at 0.

Code: Select all

label start:
    $ Aggpoints = 0
    $ Nuepoints = 0
    $ Paspoints = 0
Later on in a menu screen, we get the points added: (this is taken in direct context of the game LOL I don't expect you to understand what's going on story wise.)

Code: Select all

menu:
    "Growl at the man":
   
        "{i}Fuji growled viciously at the man{/i}"
        $ Nuepoints = +3
        show Fuji at left
        play sound "growl.wav"
        "{i}The man took a step back.{/i}"
        hide Human
        show Human at right
        "{i}He considered,{w} and then grabbed Fuji by the scruff of her neck.{/i}"
        play sound "whine.wav"
        show Fuji at left with vpunch 
        play sound "yelp.wav"
        fctc "...!!!"
        show Don at right
        dctc "Fuji! What did you do?"
        jump violent
    "Bite him!":
        $ Aggpoints = +3
        "{i}Fuji lunged at the man, fangs bared! {w} She was about to latch her jaws around his arm when{p}{/i}" 
        show Fuji at left with fade
        play sound "growl.wav"
        show Don at right with hpunch
        "{i}Don pushed Fuji down!{/i}"
        dctc "Calm down! Act nice!"
        jump down
    "Ignore him, it isn't that big of a deal.":
        $ Paspoints = +3
        jump norm
Even later, I want another menu screen to add more points and then apply them: (it's just a bunch of gibberish for now LOL I've been too stuck at this part to continue).

Code: Select all

menu: 
    "Aim for Riki's neck.":
        $ Aggpoints = +2
        jump more
        
    
    "Duck his attack.":
        $ Nuepoints = +2
        jump more
    
    "Let him bite, he can't be that strong.":
        $ Paspoints = +1
        jump more
    
label more:
    if Aggpoints == 4
        fctc fijdhiuh
    else: Nuepoints == 4
        fctc idshfisf
    else: Paspoints == 3
        "Dead"
What am I doing wrong? I keep getting expected errors when it reaches 'label more'.
"Not all who WANDER are lost."

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If Statement Help (using Points)

#2 Post by trooper6 »

You add points to your variables like so:

Code: Select all

"Aim for Riki's neck.":
        $ Aggpoints += 2
        jump more
look at the first example in the inventory and money system cookbook:
http://www.renpy.org/wiki/renpy/doc/coo ... ney_System
Last edited by trooper6 on Wed Jul 31, 2013 8:17 pm, edited 1 time in total.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: If Statement Help (using Points)

#3 Post by saguaro »

You didn't ask about this, but instead of using the italics text tags {i} in your dialogue strings, you can define an italics narrator character. It will save you some tagging.

Code: Select all

define nar = Character(None, what_italic=True)

User avatar
Suwamoto
Regular
Posts: 66
Joined: Wed Sep 05, 2012 7:36 am
Contact:

Re: If Statement Help (using Points)

#4 Post by Suwamoto »

This:

Code: Select all

"Aim for Riki's neck.":
        $ Aggpoints += 2
        jump more
And you should change the if-else statements to this o.o

Code: Select all

label more:
    if Aggpoints == 4:
        "fctc fijdhiuh"
    elif Nuepoints == 4:
        "fctc idshfisf"
    elif Paspoints == 3:
        "Dead"

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: If Statement Help (using Points)

#5 Post by PyTom »

I think it's often better to have a single variable - perhaps starting at an offset - then three variables. Aggressive actions could increment it, passive actions could decrement it, and neutral actions could leave it alone.

The problem with two or three variables is that they make conditions hard to write - and it's easy to miss a case by mistake. With a single variable, it's easy to cover the entire number line.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Wanderer
Newbie
Posts: 11
Joined: Sun Feb 10, 2013 9:04 pm
Organization: Orange Toad Studios
Contact:

Re: If Statement Help (using Points)

#6 Post by Wanderer »

Thanks everyone, especially Suwamoto and PyTom; I fixed up my errors as they were pointed out and converted everything to Aggpoints so it works better. x3 Everything works!
I'll be sure to bookmark trooper6, and the automatic italics for narrator will be really helpful, saguaro.
"Not all who WANDER are lost."

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If Statement Help (using Points)

#7 Post by trooper6 »

@PyTom, I'm away from my computer at the moment, but I'm going to look at my code when I get home to see if I converting my two variables (damnation & redemption) into just one variable based on the neat advice you wrote. I have a third variable that might be a bit tricky to deal with...as it is related to damnation, but not the same...but I think it might work!

Thanks for helping make my code more efficient and elegant!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Ocelot