Help with my code

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
Lilly
Newbie
Posts: 4
Joined: Sun Aug 26, 2018 6:52 pm
Contact:

Help with my code

#1 Post by Lilly »

Hi, this is my first post here. I am currently learning Ren'Py. I am a newbie to code, I don't know any programming language... So I am kind of messing around with Ren'Py script and figuring things out as I go for now.

Anyway, I wanted to run a little test on conditional statements. Basically a little "open the chest" game, where you open the chest, get the item inside, and then once you've gotten it once, the chest becomes empty, and you can either "proceed with the mission" or open the chest again. But I would also like to add a mechanic where Eileen gets tired of opening it for you, and warns you that if you keep making her open the chest the game will end. So I thought of adding a counter, like, Eileen opens the chest; +1 point , when 6 points are reached she tells you she's tired but she'll keep opening it, and then when 10 points are reached she tells you she got exhausted and the game ends.

I have been breaking my head over the code but due to my inexperience I can't make it work. I'd be highly grateful if anyone could help!
Here's the code:


define e = Character("Eileen")

init $ count = 0

default item = False

label start:

scene bg room

show eileen happy

e "Welcome to treasure chest!"
e "Once you've got the item, and double checked the chest, we can procceed with our mission."
e "Or, you can keep opening the chest forever if you'd like!"
e "Let's play!"

jump chest


label chest:


e "There's a treasure chest here. {p}Should I open it?"



menu:

"Yes, open it.":



if item:
e "I opened it again... But you already have the item!"
$ count += 1
jump openorproceed

else:
jump itemget


"No, leave it alone.":

if item:
e "Sure, let's leave it alone, you've already got the item anyway!"
jump openorproceed
else:
jump ignore


label openorproceed:

e "Would you like to open the chest again? {w}Or proceed with the mission?"

menu:
"Open it again!":
$ count += 1
if count < 3:
jump chest
elif count >=6:
e "Okay now, how many times will you make me open this chest? I'm tired!"
e "Fine, I'll keep opening this for you anyway."
jump chest
elif count >=9:
e "I'm exhausted! I'm warning you! If you make me open this chest again the game will end!"
jump chest
else:
e "I warned you! I got tired of opening this chest! I'm not playing this anymore!"
e "Bye!"
return
"Procced with the mission.":
jump mission





label itemget:

$ item = True



e "Congratulations! You got the item!"
jump chest


label ignore:


e "We left the chest alone."
jump chest


label mission:
e "Yay! Now that you have the item, we can proceed with the mission! Hurray!"
e "Let's go!"
return

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Help with my code

#2 Post by Matalla »

It think it would be more clear with less labels and including conditions in the menu options, but I believe this code will behave like you want. Also, next time you post a code, remember to put it between code tags (the 5th button from the left in the post editor)

Code: Select all

define e = Character("Eileen")
default count = 0 # No need for a init or $, just default
default item = False

label start:

    scene bg room

    show eileen happy

    e "Welcome to treasure chest!"
    e "Once you've got the item, and double checked the chest, we can procceed with our mission."
    e "Or, you can keep opening the chest forever if you'd like!"
    e "Let's play!"

    jump chest

label chest:

    e "There's a treasure chest here. {p}Should I open it?"

    menu:

        "Yes, open it.":

            if item:
                e "I opened it again... But you already have the item!"
                $ count += 1
                jump openorproceed

            else:
                $ count += 1 # Just a matter of preferences, are you counting the times the chest is open or the times is opened after getting the item?
                jump itemget


        "No, leave it alone.":

            if item:
                e "Sure, let's leave it alone, you've already got the item anyway!"
                jump openorproceed
            else:
                jump ignore

label openorproceed:

    e "Would you like to open the chest again? {w}Or proceed with the mission?"

    menu:
        "Open it again!":
            $ count += 1
            if count < 6: # If count < 3, like in the code you posted, it leaves 3, 4 and 5 as posible values not defined in if or elifs statements, it would go to the else part
                jump chest
            elif count >=6 and count <9: # In the code you posted >= 6 and >= 9 are not mutually exclusive, and it will only execute the first that it's true
                e "Okay now, how many times will you make me open this chest? I'm tired!"
                e "Fine, I'll keep opening this for you anyway."
                jump chest
            elif count ==9: # If it's >= 9, all the posibiliies are covered and the else part will never get executed
                e "I'm exhausted! I'm warning you! If you make me open this chest again the game will end!"
                jump chest
            else:
                e "I warned you! I got tired of opening this chest! I'm not playing this anymore!"
                e "Bye!"
                return
        "Procced with the mission.":
            jump mission

label itemget:

    $ item = True
        
    e "Congratulations! You got the item!"
    
    jump chest


label ignore:

    e "We left the chest alone."
    
    jump chest


label mission:
    e "Yay! Now that you have the item, we can proceed with the mission! Hurray!"
    e "Let's go!"
    return
Comunidad Ren'Py en español (Discord)
Honest Critique

Lilly
Newbie
Posts: 4
Joined: Sun Aug 26, 2018 6:52 pm
Contact:

Re: Help with my code

#3 Post by Lilly »

This worked like a dream! Thank you so much!!

"If count < 3, like in the code you posted, it leaves 3, 4 and 5 as posible values not defined in if or elifs statements, it would go to the else part"
"In the code you posted >= 6 and >= 9 are not mutually exclusive, and it will only execute the first that it's true"

I didn't even even think of this, I wasn't aware at all! Now I know! Thank you again!

I will be sure codes in between code tags too next time! ^^ I wasn't sure how it's done haha.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], bonnie_641