Can I edit an init variable inside my main_menu label?

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
Tage
Regular
Posts: 194
Joined: Mon Nov 01, 2004 2:18 am
Location: Memphis, TN
Contact:

Can I edit an init variable inside my main_menu label?

#1 Post by Tage »

I'm trying to do something to the effect of:

Code: Select all

init:
    $ aVariable = True

label main_menu:
    if aVariable:
        $ aVariable = False
        // Show Splash Screen
    jump _library_main_menu
The reason I want to do this is because when I click "Main Menu" from the "Continue Game" screen it reverts back to the splashscreen, and I just want it to go straight to the main menu. Or is there a better way to go about doing this?

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

This should work. It will have the side-effect of saving the variable aVariable in the savegame file, but that shouldn't affect much.

Hm... I think I will add a new label, splashscreen, that is called only once per game load. It'll be in the legendary 4.3 release, which will probably be released (if perhaps only in preview form, depending on how much documentation I get done) tomorrow.

How close are you to game release?

Tage
Regular
Posts: 194
Joined: Mon Nov 01, 2004 2:18 am
Location: Memphis, TN
Contact:

#3 Post by Tage »

It doesn't, unfortunately. :( I thought, by all means, if there was code that could do it -- That Was It.

Here's what I imagine is going on, even though I have no clue how to program in Python. Every scripting language is pretty fundamental anyway.

I imagine when I set aVariable in the init, it creates a variable for init. However, when I set aVariable inside the if statement, it creates a local variable for the if statement resulting in no changes to the init aVariable. My question is, "Does $ initialize a new variable in Python?" Because I think I just need to edit the variable instead of initializing a new one. Either way, I'll just wait for v4.3 release I guess. (hooray!) Thank you for taking the time to help me with my questions!

And, the earliest my project could finish would be in 1 month, lol. I just started on it yesterday. I have done enough for a smallish demo though. I'm calling it "Forgotten Memories" for now. I have sketched the main menu and one ugly looking ceiling (lol). Once I finish college finals next week, I'll be working on this game full time. =D I love playing renai games. So, I guess I'll just draw and plan my game for now until you release and then switch all the code over to v4.3. I guess I'll look for more music and sound effects too.

Edit: Or I could be wrong and setting a variable in an if statement doesn't create local variables in any language. Lol, I know my computer teacher codes on the board like it doesn't, but then again...she codes a lot of things incorrectly. But it would make sense if they didn't create local variables since it isn't a whole new method or anything...

Edit 2: UNLESS, (lol) label main_menu is regarded as a separate method. Oh, I don't know... Thank you for making a splashcreen label, rofl.
Last edited by Tage on Sat Dec 11, 2004 12:05 am, edited 2 times in total.

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

I imagine when I set aVariable in the init, it creates a variable for init. However, when I set aVariable inside the if statement, it creates a local variable for the if statement resulting in no changes to the init aVariable. My question is, "Does $ initialize a new variable in Python?" Because I think I just need to edit the variable instead of initializing a new one.
Unfortunately, your understanding is a bit wrong. In Ren'Py, by default, all variables are defined in the global namespace. (You can get around this by using python hide or defining and calling a function.) The dollar sign is used to introduce a python statement. Python doesn't require you to declare variables, but instead automatically creates them when you first assign to them, one of the hallmarks of a dynamic language. So in your example, you updated aVariable.

Hope this helps clear up how python and Ren'Py work.

Tage
Regular
Posts: 194
Joined: Mon Nov 01, 2004 2:18 am
Location: Memphis, TN
Contact:

#5 Post by Tage »

Phew, okay, thanks for clearing that up! I'll happily wait for that splashscreen label, lol.

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

Edit 2: UNLESS, (lol) label main_menu is regarded as a separate method. Oh, I don't know... Thank you for making a splashcreen label, rofl.
Just to clarify, in Ren'Py, all variables are global. (Except for those used entirely inside python functions, which are declared with def.) Ren'Py needs this so that it can easily determine what to save with the game is saved. Unlike traditional structured programming languages, Ren'Py is deliberately unstructured, to make loading and saving easy.

Tage
Regular
Posts: 194
Joined: Mon Nov 01, 2004 2:18 am
Location: Memphis, TN
Contact:

#7 Post by Tage »

Ahh, okay, that makes sense =)

Post Reply

Who is online

Users browsing this forum: No registered users