- Aug 15, 2017
- 14
- 6
Yes...Remove the following section:
No!and set variables inside start label:
Wrong.Defining these initial variables at the beginning of the start label will prevent unexpected behavior as the project grows in size, as well as making things clearer and more organized.
if you don't know, then give an answer that works for all scenarios. if your solution only works for a specific scenario, then you should have said so in your answer. that's just common senseThe OP did not provide any detailed information about the project, including whether there will be several updates at different times or whether these variables will actually be used later in the next chapters/days. If it is a project with a really short story, there may not even be a need for players to use saves.
Considering a scenario like this and that when a variable is not defined at game start, using the "default" statement is the same as defining the variable at the beginning of the start label, my solution is still applicable and is still a clear/organized way to deal with these initial variables in the limited context presented by the OP. I am not obligated to imagine/foresee all the different scenarios where it is necessary to give different instructions to someone who asks a question here with limited information.
What you wrote reads like: "well, it's not my fault if OP killed his mother following what I said. He should have been more explicit, and explained that 'she's ill, how can I help her' was about a human person having a flue, and not about an agonizing animal."The OP did not provide any detailed information about the project, [...]
But that's wrong. While it might let this particular example run without an error (right now), putting the initial variable declaration inside the start label has different behavior than if you properly initialized it at INIT time, using theThe solution I gave solves the immediate problem the OP presented and will allow the project to run without errors. I really don't have to guess all the needs of his project. It would be up to him to make these aspects clear somehow or wait for another answer that better meets his needs (which he apparently did).
default
statement. Something that Ren'py says on
Talking about this, strictly speaking, and obviously outside of the safe way to declare variables, his error was to writeThe OP was clear with both their problem and in sharing the applicable code.
python
in place of init python
.python
is a valid statement, and due to the way Ren'Py works, it's not explicitly an error, reason why Ren'Py didn't complained.jump
or call
), Ren'Py will continue to progress linearly into the code in the current RPY file. It's the reason why some devs achieve to have code like this:label start:
scene whatever
mc "Hello, my name is [mc.name]."
girl "Oh my god, you're so beautiful, please fuck me."
default myVar = 42
label start:
"Value is [myVar]"
python:
myVar = 24
label following:
"value is now [myVar]"
"END"
default myVar = 42
label start:
"Value is [myVar]"
python:
myVar = 24
"value is now [myVar]"
"END"
init python:
[variable declaration]
It's funny that when I wrote my first release on F95 here, I had almost my whole Intro scene written in the script.rpy file, inside the start label.Talking about this, strictly speaking, and obviously outside of the safe way to declare variables, his error was to writepython
in place ofinit python
.
Likepython
is a valid statement, and due to the way Ren'Py works, it's not explicitly an error, reason why Ren'Py didn't complained.
By design, labels aren't closed blocks, therefore when Ren'Py reach the end of a block, if there's no explicit branching (likejump
orcall
), Ren'Py will continue to progress linearly into the code in the current RPY file. It's the reason why some devs achieve to have code like this:
/!\ None of the following code are to use in your own game. /!\
In the example above, the "start" label is technically empty, and serve just as marker for free code. But this imply that something like:Python:label start: scene whatever mc "Hello, my name is [mc.name]." girl "Oh my god, you're so beautiful, please fuck me."
would works as well. In fact the second label is even optional and this too should works:Python:default myVar = 42 label start: "Value is [myVar]" python: myVar = 24 label following: "value is now [myVar]" "END"
Now, while it's not to use, it's also not totally useless knowledge.Python:default myVar = 42 label start: "Value is [myVar]" python: myVar = 24 "value is now [myVar]" "END"
It's not to use, but sometimes, especially for devs who are doing this on their freetime, your mind wander and you forgot an indentation, or do errors like this. Then like your code still works, you don't notice it, until the day where it strike back and trigger a bug.
Knowing that something dirty like this works can help you to keep in mind that "it worked before I added this" do not mean that the error isn't located in code that you wrote five months ago.
All this said, in OP code, the python block happen before the "start" label, what mean that Ren'Py never proceeded it. What OP wanted is something like:
The leading "init" tell Ren'Py that the block is to proceed before the game starts, while the "python" tell it that the following will be a Python block.Python:init python: [variable declaration]
All this obviously not changing what I said above regarding variable declaration.
label Traffic_Cop:
call intro from _intro
call a01 from _call_a01
call a02 from _call_a02
call a03a from _call_a03a
call Exit_Interview from _call_Exit_Interview
return