Help with the IF fuction

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
luckycloud7599
Newbie
Posts: 12
Joined: Wed Aug 17, 2016 11:40 pm
Projects: The Rise of Dawn
Tumblr: MossanTheDeadCow
Contact:

Help with the IF fuction

#1 Post by luckycloud7599 »

There's a small problem I'm trying to solve but I'm still a newbie on programming so can someone help me? I want the menu to be a part of the if statement as I made a menu choosing at the back, middle and front and each menu represents a character. The MC has to choose which seat she wants to take a sit and after MC chooses, she'll get special conversations exclusive to them, but the storyline (for now) is not branched yet so it'll be the same. The problem I'm having is that I don't know how to make the menu option special for the specific character.

I used this statement:

Code: Select all

$ back = False
$ middle = False
and I've already placed:

Code: Select all

$ back = True
    
    c "H-huh? Y-you're sitting with me?"
    
    "You nodded your head as you sat next to him."
    
    "A small blush formed on his face, but it was gone as soon as it appeared."
and the other:

Code: Select all

$ middle = True
    
    "You sat at the middle row of the class, waiting for the teacher to come."
    
    "You scanned around the classroom as everyone was talking cheerifully with each other."
    
    "There's an empty chair next to you, it was a window seat. You could not help but wonder about the new tranfer student."
and here's where the problem lies:

Code: Select all

g3 "Sorry but the only girl that he'll see is me and me only."

if back:

    c "Jesus, these girls are crazy when it comes to new guys... I don't see anything special about him."
    
    c "What do you think, [name]?"
    
menu:
    
    "I guess he is pretty hot.":
        
        jump hot
        
    "I think you're cuter than him.":
        
        jump cute
        
    "I don't know, there's something about him I don't understand":
        
        jump understand
After the Girl 3 spoke, it immediately went to the menu where it's supposed to be for Callisto (the character's name) only. I'll be waiting for your replies, ok guys? Please sacrifice some of your time to answer this newbie's question, thank you :D

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Help with the IF fuction

#2 Post by JeremyBenson »

You should show how you're setting the variables. Show the full code. You need a method of setting variables when you want them to set. Code is generally precederial, meaning it goes line by line.

Code: Select all


$back = false

$middle = false

$back = true

if back
   "hello"


This will set back to false, middle to false, then back to true. Meaning hello will display. Are you setting variables inside menu clicks? That would stop them from setting in order.
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Help with the IF fuction

#3 Post by JeremyBenson »

Something like this.

psuedo code

Code: Select all


   $back = false
   $middle = false
   $front = false

   character "Where do you want to sit?"

   menu:

     "back"
       $back = true
    "middle"
      $middle = true
    "front"
      $front = true

   if back

      "You sit in the back."

   if middle

       "You sit in the middle"

   if front

       "You sit in the front"

Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Help with the IF fuction

#4 Post by kivik »

Unfortunately psuedo code isn't a good way of helping others debug, as mistakes can be syntax / flow related.

Could you duplicate the code (so as to not lose it), condense the dialogues to bare bone, test to see if bug still exists, then post it here?

luckycloud7599
Newbie
Posts: 12
Joined: Wed Aug 17, 2016 11:40 pm
Projects: The Rise of Dawn
Tumblr: MossanTheDeadCow
Contact:

Re: Help with the IF fuction

#5 Post by luckycloud7599 »

My problem lies more in = "How to insert a menu in an if fuction? And how to make that menu exclusive for that single if fuction and not the whole story/code?" and believe me, the whole code for this game is quite long so I'm not sure where to start copying and pasting the necessarry code for it. And I've done what you typed, Jeremy but what I need the most is to get this code:

Code: Select all

menu:
    
    "I guess he is pretty hot.":
        
        jump hot
        
    "I think you're cuter than him.":
        
        jump cute
        
    "I don't know, there's something about him I don't understand":
        
        jump understand
For one character only without it appearing randomly during the "middle" and "front" option.

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Help with the IF fuction

#6 Post by JeremyBenson »

The reason I said to post more code was because your first post does not contain any logic at all. It's only code snippets that give us no idea as to how you're setting the variables. Anything could be happening. The best coders here-- a million times better than me-- are extremely intelligent, but they're not seers :P Best practice is to post all the logic. Everywhere that you're setting the variables is important for users to tell you what's going wrong.

Like this?

Code: Select all

label start:
    
    $sally = False
    
    "Is Sally here?"
    
    if sally == False:
        menu:
            "yes.":
                $sally = True
                
            "no.":
                $sally = False
                
    if sally == True:
        "Sally is here!"
    else:
        "Sally is not here"
        
return
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

luckycloud7599
Newbie
Posts: 12
Joined: Wed Aug 17, 2016 11:40 pm
Projects: The Rise of Dawn
Tumblr: MossanTheDeadCow
Contact:

Re: Help with the IF fuction

#7 Post by luckycloud7599 »

I tried making the short version of the original so I hope it's understandable.

Code: Select all

$ front = False 
$ middle = False
$ back = False

    c "where are you going to seat?"
    
    menu:
        
        "front":
            
            jump back
        
        "middle":
        
            jump middle
         
        "back":
            
            jump back
            
    label front:
        
        $ front = True
        
        a "You're sitting with me? Ok then."
        
    jump story1
    
    label middle:
        
        $ middle = True
        
        b "The seat next to me is free if you want."
        
    jump story1
    
    label back:
        
        c "You can't see clearly at the back but it's the bext place to get a nap."
        
    label story1
    
        t "Alright then,there's gonna be a new student here. Meet D."
        
    if front:
        
        a "What do you think of him, [name]?"
        
        menu:
            
            "Not bad.":
                
                jump notbad
                
            "...":
                
                jump ...
                
            "I like you more.":
                
                jump you
                
    label notbad: 
            
        a "I guess he is not that bad."
            
            jump story2
            
    label ...:
            
        a "Answer something."
            
            jump story2
            
    label you:
            
        a "Well I'm glad not being replaced by him."
            
            jump story2
            
    if middle:
            
        b "A new kid huh? What do you think of him?"
            
    menu:
                
            "I don't know.":
                    
                jump dontknow
                    
            "He looks weird.":
                    
                jump weird
                    
            "Meh...":
                    
                jump meh
                    
    label dontknow:
            
        "Hard to say huh?"
            
        jump story3
            
            
    label weird:
            
        "You think so?"
            
        jump story3
            
    label meh:
            
        "That's kinda mean."
            
        jump story3

    if back
        
        "Troublesome..."
        
        menu:
            
            "Indeed.":
                
                jump indeed
                
            "Seriously?":
                
                jump seriously
                
            "Not really.":
                
                jump notreally
                
    label indeed:
        
        "I know right?"
        
        jump story4
        
    label seriously?:
                     
        "What? I'm lazy."
        
        jump story4
        
    labeln notreally:
        
        "Still so troublesome."
        
        jump story4
        
    label story4:
        
        t "Well, that's it, I guess. On to class."
I want to include the menus in the if fuction and that specific character only but I'm failing miserably to do so. Is there like another code of some sort?

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Help with the IF fuction

#8 Post by JeremyBenson »

Okay, I see some code errors, but I'm not sure about overall structure.

label story1 is missing a :

in the next snippet pull back jump story2 a bit so it lines up with the other line. You want all your lines matched up with the proper indentation.

Code: Select all

 label notbad: 
            
        a "I guess he is not that bad."
            
            jump story2
if back missing : in label meh

Code: Select all

if back
        
        "Troublesome..."
        
        menu:
            
            "Indeed.":
                
                jump indeed
                
            "Seriously?":
                
                jump seriously
                
            "Not really.":
                
                jump notreally
That whole section needs tabbed in. One heads up, python will not forgive miss-matched indentation.

When you start a label

label hello:

You tab in all lines that go in that block once, and then an if statement will be in that line, and then the code in the if statement will be tabbed. Don't forget the colon.

ex

Code: Select all


label here:

    "some text tabbed in"
     if cool:
         "cool is set"
Indentation and colons are important :P
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

luckycloud7599
Newbie
Posts: 12
Joined: Wed Aug 17, 2016 11:40 pm
Projects: The Rise of Dawn
Tumblr: MossanTheDeadCow
Contact:

Re: Help with the IF fuction

#9 Post by luckycloud7599 »

You have been very helpful, Jeremy, and I only made that code because that's the much shorter version of it. But that is not answering my question. My question still lies with: how to "insert" the menu with the if fuction so for eg. if you choose an option, you'll get a special conversation with a character and that character only since the sitting arrangements are different. Each place will get a different character and different conversations but the main story line (the class itself) is the same. You'll also be able to choose an option as I plan to make several menu options for that specific character but the problem lies with the menu option itself.

The menu option will not be special to that character which is what I'm trying to solve. How to make those menus appear. In the game I'm developing, the menus for the characters still appear even though I choose a different option for the sitting arrangements and after that it flows along everything, regardless if I used the if fuction so maybe there's a code for that?

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Help with the IF fuction

#10 Post by Iylae »

Something like this?

Code: Select all

label start:

    
    "this is the main path"

    menu:

        "optional path?":
        
            $ optional_path = True
        
        "carry on main path": 
        
            $ optional_path = False
            
    if optional_path:
        
        "this is the optional path"
    
    "this is continuing the main path"
Alternate version below without using IF or python

Code: Select all

label start:

    "this is the main path"

    menu:

        "optional path?":
        
            jump optional_path_01
        
        "carry on main path": 
        
            jump main_path_01
            
        
label optional_path_01:

    "this is the optional path"
    
label main_path_01:

    "this is continuing the main path"
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

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: Help with the IF fuction

#11 Post by trooper6 »

Yes you can include menus inside of an if statement. You can also include quite a lot of stuff in your menus as well. I took a look at your large chunk of code...and mostly I'm seeing lots of errors in your indentation (you can't have labels inside labels, for example). And if you have errors in your indentation, then your game is not going to work.

Other things I noted:
-initialize your variables using default
-you don't need those labels for the various small things the person says after you choose a menu option, you can just put that dialogue in the menu.
-when you have two+ options and the answer can't be more than one of those options, use if/elif/else. It is more efficient.

Anyway, here is my rewrite of your code. Tested and it works.

Code: Select all


# Declare characters used by this game.
define a = Character('A', color="#c8ffc8")
define b = Character('B', color="#c8ffc8")
define c = Character('C', color="#c8ffc8")
define t = Character('T', color="#c8ffc8")

#Use default to declare your variable
default front = False
default middle = False
default back = False
default name = "Protag"
                   
# The game starts here.

label start:    
    c "Where are you going to sit?"
    
    menu:
        "front":
            $ front = True
            a "You're sitting with me? Ok then."
        "middle":
            $ middle = True
            b "The seat next to me is free if you want."
        "back":
            $ back = True
            c "You can't see clearly at the back but it's the bext place to get a nap."
    
    t "Alright then,there's gonna be a new student here. Meet D."
    
    if front:
        a "What do you think of him, [name]?"
        
        menu:
            "Not bad.":
                a "I guess he is not that bad."
            "...":
                a "Answer something."
            "I like you more.":
                a "Well I'm glad not being replaced by him."
    elif middle:        
        b "A new kid huh? What do you think of him?"
        
        menu:
            "I don't know.":
                b "Hard to say huh?"
            "He looks weird.":
                b "You think so?"
            "Meh...":
                b "That's kinda mean."
    else:    
        c "Troublesome..."
    
        menu:
            "Indeed.":
                c "I know right?"
            "Seriously?":
                c "What? I'm lazy."
            "Not really.":
                c "Still so troublesome."
    
    t "Well, that's it, I guess. On to class."
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

luckycloud7599
Newbie
Posts: 12
Joined: Wed Aug 17, 2016 11:40 pm
Projects: The Rise of Dawn
Tumblr: MossanTheDeadCow
Contact:

Re: Help with the IF fuction

#12 Post by luckycloud7599 »

Ok, problem solved for that. But what about the continued story? Is it still the same and we use the if fuction or the elif, etc? For eg. after the teacher starts and explains a few things or so before asking a question to MC and the different characters commented on her answer? Cuz when I changed the code in the original (as the one above is a much shorter version of it) I still have the same problem. I'm still a newbie at this >.<

EDIT: Nevermind, I found it >.< Thanks guys :D

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: Help with the IF fuction

#13 Post by trooper6 »

You just have to think through what you want to happen in an orderly and linear fashion and then figure out how you would order it.

You said: "after the teacher starts and explains a few things or so before asking a question to MC and the different characters commented on her answer?"

So let me show you how I break this down in my head:

1) The teacher starts and explains a few things. (So that will just be the normal talking).
2) The teacher asks a question to the MC and the MC has a choice of different answers. (That sounds like a menu).
3) The different characters sitting next to the MC will comment on her answer. (Since the responses are dependent on the answer, I see the responses being under each answer...and since the response will depend on which person is sitting next to her, that is were the if will be).

A sketch would look like:

Teacher Talks
Teacher asks a question
Menu of Answers:
----Answer 1:
--------if front:
------------Char A makes comment
--------elif middle:
------------Char B makes comment
--------else:
------------Char C makes comment
----Answer 2:
--------if front:
------------Char A makes comment
--------elif middle:
------------Char B makes comment
--------else:
------------Char C makes comment
----Answer 3:
--------if front:
------------Char A makes comment
--------elif middle:
------------Char B makes comment
--------else:
------------Char C makes comment
Teacher talks more
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: Google [Bot], Ocelot, Sirifys-Al