Issue with Variables

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
aussieducky
Regular
Posts: 31
Joined: Sat Dec 27, 2014 8:43 pm
Projects: =
Tumblr: aussiebunny
Contact:

Issue with Variables

#1 Post by aussieducky »

In my game, there's a door locked by code. Once unlocked, I want the player to be able to pass between the hidden room and the door room without having to re-enter the code or re-read the protag's text. I've tried by myself, but my code isn't working.

Code: Select all

label CodeDoor:
    if dooropen == True:
        jump backroomfirst
        
    else:
        h "Whoa.....What's up with this door?"
        h "It's metal. Could it be steel?"
        h "Why is something like {i}this{/i} here? This house is worn-down and falling apart. This is a state of the art security door!"
        h "What in the world could be behind it?"
        h "Looks like a number code is required to open it."
    
        $ answer = renpy.input(_("Code:"))
    
        "[answer]"
    
        if answer =="7":
            h "The door opened."
            $ dooropen == True
        
            jump backroomfirst
        
        else:
            h "Damn, that was wrong. The door wouldn't budge."
            h "I need to find the code."
        
            jump BRDoorF[/c]

This is at the Start label, in case its important:

[c]label start:
    $ found_cannedpeas = False
    $ found_beefjerky = False
    $ found_machete = False
    $ found_salmon = False
    $ found_codepapers = False
    $ found_gloves = False
    $ dooropen = False
    
    init:
        $ faright = Position(xpos=0.80, xanchor=0.5, ypos=0.5, yanchor=0.5)
    
        $ flash = Fade(.25, 0, .75, color="#fff")
As is, the game just repeats the text. Help? ;-;
Last edited by aussieducky on Mon Aug 10, 2015 4:41 am, edited 1 time in total.
I am a teenager who would like, very much, to finish a visual novel ;D

I don't know much about coding, but I'll try not to be a bother.

Currently working on: "Blackout"

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Issue with Variables

#2 Post by mobychan »

first, if you show us your code, use [ code][ /code] (without spaces) so we can see how you indented your code^^

your problem is you wrote

Code: Select all

dooropen == True
instead of

Code: Select all

dooropen = True
for assinging true to the variable^^

Code: Select all

label CodeDoor:
    if dooropen == True:
        jump backroomfirst

    else:
        h "Whoa.....What's up with this door?"
        h "It's metal. Could it be steel?"
        h "Why is something like {i}this{/i} here? This house is worn-down and falling apart. This is a state of the art security door!"
        h "What in the world could be behind it?"
        h "Looks like a number code is required to open it."

        $ answer = renpy.input(_("Code:"))

        "[answer]"

        if answer =="7":
            h "The door opened."
            $ dooropen = True # <-- this was the problem

            jump backroomfirst

    else:
        h "Damn, that was wrong. The door wouldn't budge."
        h "I need to find the code."

        jump BRDoorF

This is at the Start label, in case its important:

label start:
    $ found_cannedpeas = False
    $ found_beefjerky = False
    $ found_machete = False
    $ found_salmon = False
    $ found_codepapers = False
    $ found_gloves = False
    $ dooropen = False

init:
    $ faright = Position(xpos=0.80, xanchor=0.5, ypos=0.5, yanchor=0.5)

    $ flash = Fade(.25, 0, .75, color="#fff")

User avatar
aussieducky
Regular
Posts: 31
Joined: Sat Dec 27, 2014 8:43 pm
Projects: =
Tumblr: aussiebunny
Contact:

Re: Issue with Variables

#3 Post by aussieducky »

Oh, sorry! D: I thought the button I clicked would do that, but apparently not :P

Also, thank you! The code works perfectly now.

Could I ask you one more variables question? There's one object in the game I want the player to click three times before an event is triggered. I know how to trigger an even involving multiple objects, but not just one ;-;
I am a teenager who would like, very much, to finish a visual novel ;D

I don't know much about coding, but I'll try not to be a bother.

Currently working on: "Blackout"

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Issue with Variables

#4 Post by mobychan »

How about just increasing a number everytime the player clicks on it?

Code: Select all

variable_name += 1
Then later on just check for it's value:

Code: Select all

if variable_name == 3:

User avatar
aussieducky
Regular
Posts: 31
Joined: Sat Dec 27, 2014 8:43 pm
Projects: =
Tumblr: aussiebunny
Contact:

Re: Issue with Variables

#5 Post by aussieducky »

mobychan wrote:How about just increasing a number everytime the player clicks on it?

Code: Select all

variable_name += 1
Then later on just check for it's value:

Code: Select all

if variable_name == 3:
I'm sorry, but where in the code would these go?
I am a teenager who would like, very much, to finish a visual novel ;D

I don't know much about coding, but I'll try not to be a bother.

Currently working on: "Blackout"

Myran
Newbie
Posts: 2
Joined: Sun Aug 09, 2015 8:48 am
Contact:

Re: Issue with Variables

#6 Post by Myran »

Basically, at the start you have to set a variable that will count the amount of times that the object was clicked, let's call the variable click_amount:

Code: Select all

label start:
    $ click_amount = 0
I assume clicking on the object calls a function. The function should contain the following code:

Code: Select all

click_amount += 1
if click_amount == 3:
    [event code goes here]
This will increase the variable by one every time you click and, on the third click, will carry out the specified code.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Issue with Variables

#7 Post by Onishion »

Keep in mind that unless the code is inside a python block, you'll have to use "$ click_amount += 1" rather than just "click_amount += 1"

But yeah, there are all sorts of ways you can do this and each has different options. You could check it with "if click_amount < 3:" and then have it skip to something else in that case, or you could have "if click_amount >= 3:" which would allow you to track clicks past 3 but the door would still work after that. it all depends on what you want to do with it.

User avatar
aussieducky
Regular
Posts: 31
Joined: Sat Dec 27, 2014 8:43 pm
Projects: =
Tumblr: aussiebunny
Contact:

Re: Issue with Variables

#8 Post by aussieducky »

This has been extremely helpful and I really appreciate it. Thank you all :)
I am a teenager who would like, very much, to finish a visual novel ;D

I don't know much about coding, but I'll try not to be a bother.

Currently working on: "Blackout"

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]