Expected Statements and Slow Text

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
dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Expected Statements and Slow Text

#1 Post by dIgItayel »

Hi guys :) I'm currently trying to figure out how to make my default text style slow text (I've looked online but all of the threads so far are really confusing for me) and what my problem is in part of my script.
For the script problem, here's the error file:

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 97: expected statement.
spirit = True
^

Ren'Py Version: Ren'Py 6.99.12.4.2187

Basically what I was trying to do was make a certain choice option only show if the player chose a specific thing earlier. The menu itself would still show if the player did not choose the specific thing earlier in the game, it's just that one of the choices would no longer show. In my actual script, I do have the python symbol ($) before the word spirit. Here's my code for what I just explained:


"Are you a spirit?":
$ spirit = True

(So, if the player chooses to ask that, then "spirit" should become true.)

"Are you his guardian?" if spirit == True:

(I also have this as a later choice. Two other questions are also present, but they can be asked no matter what the player did earlier in the game.)

Thanks~

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Expected Statements and Slow Text

#2 Post by famakki1 »

Well this is a brute force method since I am a beginner myself but maybe this works:

Code: Select all

label start:

   a "Yada yada"

   b "Yada yada"

   c "Now I will branch story into two parts."

   if spirit = True:
     jump spirittrue

   jump spiritfalse

label spirittrue:
   menu:
     "Are you a spirit?":
         jump tostory
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

label spiritfalse
   menu:
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

label tostory:
   a "Story continues"

Of course you can control what each label does...I guess what I am saying is make 2 labels with 2 menus, with one label only accessible if $ spirit = True. Indentations may not be accurate in my code.

Furthermore, if you want to include the choice but make it unselectable...modify the choice screen to:

Code: Select all

screen choice:

    window: 
        style "menu_window"        
        xalign 0.5
        yalign 0.5
        
        vbox:
            style "menu"
            spacing 2
            
            for caption, action, chosen in items:
                
                if action:  
                    
                    if " (disabled)" in caption:
                        $ caption = caption.replace(" (disabled)", "")
                        button:
                            action None
                            style "menu_choice_button"
                            
                            text caption style "menu_choice"
                    else:
                        button:
                            action action
                            style "menu_choice_button"

                            text caption style "menu_choice"
                    
                else:
                    text caption style "menu_caption"
Then in the menu:

Code: Select all


label spiritfalse:
   menu:
     "Are you a spirit?" (disabled):
         jump tostory
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

This thread is the original one viewtopic.php?f=8&t=25453&p=313338&hili ... ce#p313338
Credit to bg_nocturnal

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Expected Statements and Slow Text

#3 Post by dIgItayel »

famakki1 wrote:Well this is a brute force method since I am a beginner myself but maybe this works:

Code: Select all

label start:

   a "Yada yada"

   b "Yada yada"

   c "Now I will branch story into two parts."

   if spirit = True:
     jump spirittrue

   jump spiritfalse

label spirittrue:
   menu:
     "Are you a spirit?":
         jump tostory
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

label spiritfalse
   menu:
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

label tostory:
   a "Story continues"

Of course you can control what each label does...I guess what I am saying is make 2 labels with 2 menus, with one label only accessible if $ spirit = True. Indentations may not be accurate in my code.

Furthermore, if you want to include the choice but make it unselectable...modify the choice screen to:

Code: Select all

screen choice:

    window: 
        style "menu_window"        
        xalign 0.5
        yalign 0.5
        
        vbox:
            style "menu"
            spacing 2
            
            for caption, action, chosen in items:
                
                if action:  
                    
                    if " (disabled)" in caption:
                        $ caption = caption.replace(" (disabled)", "")
                        button:
                            action None
                            style "menu_choice_button"
                            
                            text caption style "menu_choice"
                    else:
                        button:
                            action action
                            style "menu_choice_button"

                            text caption style "menu_choice"
                    
                else:
                    text caption style "menu_caption"
Then in the menu:

Code: Select all


label spiritfalse:
   menu:
     "Are you a spirit?" (disabled):
         jump tostory
     "Choice 2":
         jump tostory
     "Choice 3:
         jump tostory

This thread is the original one viewtopic.php?f=8&t=25453&p=313338&hili ... ce#p313338
Credit to bg_nocturnal
The thing is, the spirit = true code itself isn't working. I keep getting the expected statement error.

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Expected Statements and Slow Text

#4 Post by famakki1 »

Instead of true/false, use 0 and 1.

so define...

In the script:

Code: Select all

$ spirit = 1
This should work.

I think for text you need to 'assign' in if statement (double equal signs), ie. $ spirit = True, then declare as:

Code: Select all

if spirit == True: #double equal signs
   jump tostory
EDIT:

I quickly tested the following code and it works:

Code: Select all

label start:
    
    scene white    

    "You've created a new Ren'Py game."
    
    $ spirit = True
    
    if spirit == True:   #if you comment the jump and if statement, game will return to main menu.
        jump spirit        #otherwise game should jump to label spirit
        
    return
        
label spirit:
    "spirit is true"

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Expected Statements and Slow Text

#5 Post by dIgItayel »

famakki1 wrote:Instead of true/false, use 0 and 1.

so define...

In the script:

Code: Select all

$ spirit = 1
This should work.

I think for text you need to 'assign' in if statement (double equal signs), ie. $ spirit = True, then declare as:

Code: Select all

if spirit == True: #double equal signs
   jump tostory
EDIT:

I quickly tested the following code and it works:

Code: Select all

label start:
    
    scene white    

    "You've created a new Ren'Py game."
    
    $ spirit = True
    
    if spirit == True:   #if you comment the jump and if statement, game will return to main menu.
        jump spirit        #otherwise game should jump to label spirit
        
    return
        
label spirit:
    "spirit is true"
I tried that, but it still said "spirit" was undefined.

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Expected Statements and Slow Text

#6 Post by famakki1 »

Can you show your code on how you are defining the variable for 'spirit'?

If you copy and paste the above example into a new project, it works fine, so you can replicate that but I think the issue is related to the way you are defining the variable.

EDIT: Make sure you are using the 'dollar' sign. ie. $ spirit = True since your error is reading:

File "game/script.rpy", line 97: expected statement.
spirit = True
^

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Expected Statements and Slow Text

#7 Post by dIgItayel »

Here's the code for defining "spirit"

Code: Select all

 "Are you a spirit?":
            $ spirit = True
            "So, Sera...You're a spirit, right?"
            
And for the menu:

Code: Select all

 menu:
        "What do you want to talk about?"
        
        "Where do you guys live?":
            pn "So do you guys live close to the campus?"
            s "Oh! We live together, actually. We're roommates! We live about a mile off campus in this little rental house."
            n "Living with Sera is actually awful. Please save me."
            s "Oh shut up, you know you looooove me!"
            n "A-As if!"
            jump finding_out
            
        "Are you two dating?":
            pn "So, uh, are you two...dating?"
            n "W-WHAAAAT?!"
            s "Nonononononono! We're not dating!"
            n "E-Ew. No."
            s "Besides, I'm like, the most gay person ever. Like, ever. Feel free to call me the Ultimate Gay. And Naois here is about as straight as a circle."
            n "S-Sera!"
            s "Oh, I'm sorrrrrry. You're sensitive~ Hehehe"
            jump finding_out
            
        "Are you his guardian?" if spirit == True:
            pn "Are you Naois' Guardian?"
            jump naois_guardian
            

famakki1
Regular
Posts: 55
Joined: Wed Oct 12, 2016 7:40 am
Contact:

Re: Expected Statements and Slow Text

#8 Post by famakki1 »

I don't know what the issue could be, however, I have attached a Renpy project containing your code which is working, which can help I hope.
dIgItayel wrote:Here's the code for defining "spirit"

Code: Select all

 "Are you a spirit?":
            $ spirit = True
            "So, Sera...You're a spirit, right?"
            
I do not know if you made this part of menu, but this code can't work unless part of a menu.
Attachments
spirittrue.rar
(333.87 KiB) Downloaded 17 times

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Expected Statements and Slow Text

#9 Post by dIgItayel »

famakki1 wrote:I don't know what the issue could be, however, I have attached a Renpy project containing your code which is working, which can help I hope.
dIgItayel wrote:Here's the code for defining "spirit"

Code: Select all

 "Are you a spirit?":
            $ spirit = True
            "So, Sera...You're a spirit, right?"
            
I do not know if you made this part of menu, but this code can't work unless part of a menu.
That's basically the exact code I have.

Code: Select all

 menu:
        "What do you say?"

        "Is this a safe neighborhood?":
           pn "So, uh... Is this a safe neighborhood?"
           s "Oh! Well, not really if I'm being honest... There's a lot of poverty near here, so there's a lot of crime..."
           pn "Does that include-"
           s "Yeah. Murder. Look, don't worry about it. Just stay near the campus and don't go seekin' trouble."
           
           jump meet_naois
            
    

        "Are you a spirit?":
            $ spirit = True
            "So, Sera...You're a spirit, right?"
            
            jump spirit_sera
It's weird, the code works when I select "Are you a spirit?", but if I select "Is this a safe neighborhood?" it doesn't work. Here's the error I get after choosing "Is this a safe neighborhood?" and playing on:

Code: Select all

While running game code:
  File "game/script.rpy", line 189, in script
    menu:
  File "game/script.rpy", line 210, in <module>
    "Are you his guardian?" if spirit == True:
NameError: name 'spirit' is not defined
It says it's not defined, but it works just fine when I choose "Are you a spirit?"

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Expected Statements and Slow Text

#10 Post by korova »

dIgItayel wrote: It says it's not defined, but it works just fine when I choose "Are you a spirit?"
Because it's the only time you actually "define" the variable (= make it exist)
If you don't choose "Are you a spirit", the "spirit" variable is not defined.

You'll have to put

Code: Select all

default spirit = False
at the beginning of your script.
This way, the variable always exists, and become true only if you choose "Are you a spirit"

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Sugar_and_rice