How to make a screen that changes during the game?

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
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

How to make a screen that changes during the game?

#1 Post by Karizu » Mon Apr 11, 2016 7:17 am

Hi everyone, my problem is very simple, so I'm being as concise as possible.
In my project I have created a long series of the same screen with unlockable contents (a sort of homemade imagemap CG Gallery) and I wanted the screen to change every time I wrote a "flag" in the script (correct me if I'm using inapt words). So I tried using this code:

Code: Select all

screen extra_events:
    tag menu
    
    if persistent.unlock == "CG1":
        use extra_events_1
    if persistent.unlock == "CG2":
        use extra_events_2
    else:
        use extra_events_0
in the screen.rpy file, whit the relative screens, and this:

Code: Select all

$ persistent.unlock = "CG1"
$ persistent.unlock = "CG2"
in script.rpy, obviously each line located just before the different pictures appeared.

The problem is that if I use this kind of code, the only "persistent.unlock" string considered by renpy is the last one, so that if I don't go over the last "persistent.unlock" string playing the game, nothing in my events screen changes and the code "prints" the else command, making me see the "extra_events_0" screen. That being said, I understand this code won't work because the persistent can be used only with a choice menu to change the main menu appearance after a choice for example, but it actually seems strange to me that a variable system like the one I need doesn't exist at all. So, if you have some tips to tell me, I'd appreciate.
Thank you in advance.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to make a screen that changes during the game?

#2 Post by xela » Mon Apr 11, 2016 7:34 am

You prolly want if/elif/else, not if/if/else. And persistent works everywhere... not just in main_menu.
Like what we're doing? Support us at:
Image

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

Re: How to make a screen that changes during the game?

#3 Post by Karizu » Mon Apr 11, 2016 7:57 am

Yes, you were totally right! This was the problem. Thank you very much, you definitely saved me. :D
So, if i use "elif" for the other variables , I sould be able to run my game correctly, am I right?
And I'm very sorry for the silly question but even If I did some researches, I can't actually catch what "elif" means exactly.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to make a screen that changes during the game?

#4 Post by xela » Mon Apr 11, 2016 8:18 am

http://stackoverflow.com/questions/9271 ... ifs-python

it will work if rest of the choices are just more options of the same.
Like what we're doing? Support us at:
Image

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

Re: How to make a screen that changes during the game?

#5 Post by Karizu » Mon Apr 11, 2016 8:32 am

Ok, this makes sense. Thank you very much for your time, you were very helpful! :)

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

How to make nested conditions work?

#6 Post by Karizu » Tue Apr 12, 2016 6:10 am

Now I have another little question closely related to variables. I tried using some nested conditions, like this:

Code: Select all

screen extra_events:
    tag menu
    
    if persistent.unlock == "CG1":
        use extra_events_1
    elif persistent.unlock == "CG2":
        use extra_events_2
    elif persistent.unlock == "CG3":
        use extra_events_3
    elif persistent.unlock == "CG4":
        if persistent.unlock == "CG3":
            use extra_events_4
        else:
            use extra_events_4no3
but can't figure out what I'm doing wrong now. The error that the program gives me is the following:

Code: Select all

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


File "game/screens.rpy", line 542: u'else' is not a keyword argument or valid child for the screen statement.
    else:
        ^

Ren'Py Version: Ren'Py 6.99.10.1227
I have created a screen with CG3 and CG4 both unlocked, but CG3 is unlockable only by doing a particular choice, so that if you skip it, you should see the CG4no3 screen, where CG4 is unlocked but CG3 is not, and the gamer will understand that something's missing. I thought that this kind of nested conditions would have been reasonable, but this is the error, so I'm probably misunderstanding which the correct syntax is in this case.
Thank you in advance another time.

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

Re: How to make a screen that changes during the game?

#7 Post by Karizu » Tue Apr 12, 2016 1:11 pm

Probably I better open a new topic with a new title for my new problem, just because I googled some key-words related to nested conditions in renpy but I couldn't find anything, so maybe it would be useful for some other people too. I'm also putting the tag "solved" on this particular topic.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to make a screen that changes during the game?

#8 Post by xela » Tue Apr 12, 2016 3:02 pm

This looks ok unless I'm missing something... so it should just work.
Like what we're doing? Support us at:
Image

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

Re: How to make a screen that changes during the game?

#9 Post by Karizu » Wed Apr 13, 2016 4:53 am

Yes, it should work to me too, but it doesn't. It continues giving me the error I posted before, as "else" weren't a valid child for an elif condition. At this point, I don't actually know how to fix it.
Akumangel: The Madhouse Swing: an an investigative-noire visual novel entirely set between the walls of a prestigious mental hospital situated on the outskirts of New York City, during the 40s.
Julia Maine - a young and peculiar detective living in uptown NYC - discovers from her father's old notes that many important men and women, coming from politics or high society, have mysteriously disappeared over the years, under unknown circumstances.
All the researches seem to point to the old St Jeremy House, an ancient manor converted into an asylum, but beside these poor informations, the notes give no sign of hard evidence.
During a period of forced unemployment caused by the critic loss of interesting cases, Julia decides to get hospitalized in the madhouse in order to investigate and resolve the case, firmly convinced that the most of the "mad" patients have actually been kidnapped by some secret organization.
Website: http://akumangeltms.blogspot.com

User avatar
Karizu
Newbie
Posts: 19
Joined: Mon Apr 11, 2016 6:28 am
Completed: AKUMANGEL (IT)
Projects: Akumangel: The Madhouse Swing (ENG-IT)
Organization: Spin.to Studios
Soundcloud: spin-to-studios
Contact:

Re: How to make a screen that changes during the game?

#10 Post by Karizu » Wed Apr 13, 2016 5:24 am

Ok, I mange to solve the problem. It was caused by a simple unalignment issue caused by some bug in my editor. Thank you for your answers anyway, you were very helpful.
Akumangel: The Madhouse Swing: an an investigative-noire visual novel entirely set between the walls of a prestigious mental hospital situated on the outskirts of New York City, during the 40s.
Julia Maine - a young and peculiar detective living in uptown NYC - discovers from her father's old notes that many important men and women, coming from politics or high society, have mysteriously disappeared over the years, under unknown circumstances.
All the researches seem to point to the old St Jeremy House, an ancient manor converted into an asylum, but beside these poor informations, the notes give no sign of hard evidence.
During a period of forced unemployment caused by the critic loss of interesting cases, Julia decides to get hospitalized in the madhouse in order to investigate and resolve the case, firmly convinced that the most of the "mad" patients have actually been kidnapped by some secret organization.
Website: http://akumangeltms.blogspot.com

Post Reply

Who is online

Users browsing this forum: No registered users