Variable menu choices, a tell points code, and changed names

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
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Variable menu choices, a tell points code, and changed names

#1 Post by valeatory » Mon Apr 23, 2007 4:14 pm

Hello, this is my first post here, and I have been having a few problems with my Ren'py game. I am not an experienced programmer, so I was hoping someone here could help me with my numerous problems. For one thing, I wanted another menu option to appear, depending on a variable, but it gives me errors every time I try it. I also couldn't find anywhere that told me how to make the text box tell you exactly how many food_points you have. Is there a way to make it so that when a character tells you his name in an optional text, it is changed from "Villager" to "Bob" everywhere? Heehee... I wonder if I am trying for too much.... Help please?

User avatar
PyTom
Ren'Py Creator
Posts: 15445
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:

#2 Post by PyTom » Mon Apr 23, 2007 4:26 pm

Here, we have a third menu item that only appears if food_points > 10:

Code: Select all

menu:
    "Eat the chicken.":
         ...
    "Eat your veggies:":
         ...
     "I'm full." if food_points > 10:
         ...
To make food_points show up in a text box, write:

Code: Select all

"I realize that I have %(food_points)d food points."
To change bob's name:

Code: Select all

init:
    $ bob = DynamicCharacter("bob_name")

label start:

    $ bob_name = "Villager"

    bob "Welcome to our village."
    
    $ bob_name = "Bob"

    bob "My name is Bob Phorapples."
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

#3 Post by valeatory » Mon Apr 23, 2007 4:42 pm

I put it in, and it says that bob_name is not defined. (And because of the way my game is wrietten, I can't get past it to check the other things!)
Wait, nevermind. I was loading a save that hadn't hit the definition yet, so when I moved the definition to where it could see it, it was fine. Still checking the rest...
Last edited by valeatory on Mon Apr 23, 2007 4:45 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 15445
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:

#4 Post by PyTom » Mon Apr 23, 2007 4:43 pm

You need to set bob_name to something right after the start label, before the first time you use bob.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

#5 Post by valeatory » Mon Apr 23, 2007 4:48 pm

Okay, I fixed bob, but when I try to look at the menu option, it crashes, telling me that the line where my menu starts is a problem, even though I'm fairly sure everything is all right. Is it another mindless mistake?

User avatar
PyTom
Ren'Py Creator
Posts: 15445
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:

#6 Post by PyTom » Mon Apr 23, 2007 4:59 pm

It really depends on what the message says. I need the full text of the message, and also the source code to the menu.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

#7 Post by valeatory » Mon Apr 23, 2007 5:08 pm

Sorry, I just read the questions sticky. :oops: Should have done that earlier. I ran it again, and the problem line changed.

Code: Select all

SyntaxError: invalid syntax (line 1)

While executing game script on line 332 of C:\Games\renpy-6.1.0\Val's Adventure/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

  File "C:\Games\renpy-6.1.0\renpy\bootstrap.py", line 166, in bootstrap
  File "C:\Games\renpy-6.1.0\renpy\main.py", line 275, in main
  File "C:\Games\renpy-6.1.0\renpy\main.py", line 92, in run
  File "C:\Games\renpy-6.1.0\renpy\execution.py", line 97, in run
  File "C:\Games\renpy-6.1.0\renpy\ast.py", line 762, in execute
  File "C:\Games\renpy-6.1.0\renpy\exports.py", line 289, in menu
  File "C:\Games\renpy-6.1.0\renpy\python.py", line 886, in py_eval
  File "C:\Games\renpy-6.1.0\renpy\python.py", line 177, in py_compile
  File "compiler\transformer.pyo", line 52, in parse
  File "compiler\transformer.pyo", line 124, in parseexpr
SyntaxError: invalid syntax (line 1)

While executing game script on line 332 of C:\Games\renpy-6.1.0\Val's Adventure/game/script.rpy.

Ren'Py Version: Ren'Py 6.1.0b
This is the context. (Warning, it's really long)

Code: Select all

menu:
    "Wood sword. (100G)":
        if gold_points <100:
            s "I'm sorry, you can't afford this weapon...." 
            s "Come again when you have more money."
            jump buystore
        s "A poor weapon. Deals minimal damage. Costs 100G."
        s "buy it?"
        menu:
            "Yes.":
                $ woodsword=True
                $ gold_points -=100
                jump buystore
            "No.":
                jump buystore
    "Food. (30G)":
        if gold_points <30:
            s "I'm sorry, you can't afford this item..."
            s "Come again when you have more money."
            jump buystore
        s "The standard adventuring rations. Three servings for 30G."
        s "Buy some?"
        menu:
            "Yes.":
                $ food_points +=3
                $ gold_points -=30
                jump buystore
            "No.":
                jump buystore
    "Shiny Thing (500G)":
        if gold_points <500:
            s "I'm sorry, you can't afford this... Object. "
            s "So please come again when you have more money."
            jump buystore
        s "A Shiny Thing. I'm not sure exactly what it does, but my female customers love it..."
        s "Buy one for 500G?"
        menu:
            "Yes.":
                $ ShinyThing = True
                $ gold_points -=500
                jump buystore
            "No.":
                jump buystore
    "Another Menu option" if ShinyThing = True:
        m "the result to this option."
        jump buystore
    "<-":
        jump store

User avatar
monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#8 Post by monele » Mon Apr 23, 2007 5:14 pm

Code: Select all

if ShinyThing = True
into

Code: Select all

if ShinyThing == True
maybe ?... *not sure*

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

#9 Post by valeatory » Mon Apr 23, 2007 5:17 pm

It worked! Thanks for helping me, PyTom and Monele, This will make it work so much better!

User avatar
PyTom
Ren'Py Creator
Posts: 15445
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:

#10 Post by PyTom » Mon Apr 23, 2007 6:18 pm

Good catch by monele... solving the problem before I even had a chance to read it.

One thing is I would probably write "if ShinyThing" rather than "if ShinyThing == True".
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

#11 Post by valeatory » Mon Apr 23, 2007 7:01 pm

Alright, that does make it easier. I was going to also see if some of them would respond to: if place == travtown, because I wanted all of the towns to sell different items while still not requiring me to rewrite the store code from scratch every time. Haven't tried it quite yet, though. :D

Post Reply

Who is online

Users browsing this forum: No registered users