I was going through a game's code and noticed a file called variables.rpy
Code:
label variables:
#character relationship variables
default lilyRS = 0
$ persistent.lilyMet = False
# And a lot more variables after
# ......
return
As far as i can see there is no `jump variables` anywhere. (searched using grep) How do these variables actually get defined? If control never reaches this label
It's possible they are calling the label, given that it has a return statement at the end. Either way, I do not recommend defining variables inside labels like this.
It's possible they are calling the label, given that it has a return statement at the end. Either way, I do not recommend defining variables inside labels like this.
Interesting, just checked it doesn't seem to be called using the call statement either. Is there something I can do like put a `print(stacktrace)` or something similar inside the label that lets me see where exactly it's getting called from?
I did a search for "variables" and there are no references to it at all. However, when Ren'Py loads, even if inside a label, it will read the default keyword and set the variable. So the label doesn't actually have to be jumped to or called... it's defined at init.
default is one of a list of commands that, in effect, are executed when the game starts.
The label has nothing at all to do with them and is likely just the author copy/pasting code from someone who didn't understand it either.
Things like default, define and image are NOT executed at runtime.
When you hit the [START] button on almost every game, those default values are loaded - regardless of where the statements are located within the code.
For much the same reason, those same statements are treated as comments while the script is running (since they've already been executed).
As with all programming languages, there are some caveats with all that. But that's the basics of it.
I wrote this example for a another thread which highlights the point...
Python:
label start:
"*** START ***"
$ myvar1 += 1
"value is [myvar1]."
default myvar1 = 5
"new value is [myvar1]."
"*** THE END ***"
Will display 6 and 6, not 6 and 5 (or even 1 and 5).
Most developers will put statements like these at the top of the scripts, or create separate scripts to hold them. It's purely for organizing things, RenPy doesn't care. But it makes sense to the programmer and will make their lives easier in the future, if they know where to find things that are initialized.
Edit: (for a bit of clarity)...
default should be used for variables where the value will be (or is likely to be in the future) changed by the script. define should be used for variables that will remain unchanged while the script is running.
label variables:
#character relationship variables
default lilyRS = 0
$ persistent.lilyMet = False
# And a lot more variables after
# ......
return
I just went back and looked at this again and it works... but not for the reasons the original author probably thought.
label variables: - not needed. default lilyRS = 0 - is fine. But doesn't need to be indented (or within a label). $ persistent.lilyMet = False - will never be executed, unless a call variablesis added to the script. return - no more needed than the label.
They get away with the persistent variable, because they wanted the default value to be False.
But that line of code is never run and so the variable will never be set. But a peculiarity of persistent variables is that they don't cause runtime errors if they don't exist and will generally behave like an empty string and/or False - depending on how they are used. The end result is the same for this script, but by accident rather than design.
Personally, I would use default persistent.lilyMet = False - since this is clearly a variable that will be changed with the actions of the player and following that rule is safer when starting out. I could explain why it doesn't strictly need to be default like other variables - but that would just muddy the waters and honestly just go into a level of detail not needed for this type of question. Keep it simple - if it's going to change, it should be default.
Can someone tell me how to get this variables.rpy file in the game folder? I used Unren to do this but still couldn't get this variables.rpy file. The game in question is Demon Curse
Can someone tell me how to get this variables.rpy file in the game folder? I used Unren to do this but still couldn't get this variables.rpy file. The game in question is Demon Curse
RenPy doesn't care what the files are called. Just because one game has a variables.rpy, doesn't mean other games will have an identical file. Demon Curse does not have a variables.rpy file.
You've picked an abomination of a game (at least, as far as variables go).
For example, the character names are defined within \renpy\common\00action_menu.py.
I can't begin to explain how odd that is. I'm sure the developer has their reasons... I can't imagine what they are.
RenPy doesn't care what the files are called. Just because one game has a variables.rpy, doesn't mean other games will have an identical file. Demon Curse does not have a variables.rpy file.
You've picked an abomination of a game (at least, as far as variables go).
For example, the character names are defined within \renpy\common\00action_menu.py.
I can't begin to explain how odd that is. I'm sure the developer has their reasons... I can't imagine what they are.
Hey thanks man. I am a layman here can you guide me how to change the stamina and lust in that game. Someone in that games thread explained that there is a variables.rpy file and the stamina and lust bar can be altered.
Hey thanks man. I am a layman here can you guide me how to change the stamina and lust in that game. Someone in that games thread explained that there is a variables.rpy file and the stamina and lust bar can be altered.
Yeah. Okay. This guy is an arse.
Right at the bottom of their code for handling the advancing of time is a bit of code that basically says "if the player has enabled the console, ZERO OUT the player's progress".
First thing you're going to need to do is edit the \renpy\common\00action_menu.py file and remove those lines from the code.
Oh... dear gods, it gets worse.
They've also hidden some code in /renpy/common/00preferences.py too.
Python:
if config.console == True:
jump turn_off
# then later...
if not xconfig:
jump turn_off
The label turn_off: again zeroes out the player's progress and in this case, calls the player a cheater then quits to the main menu.
All 4 of those lines need to be removed too.
Oh wait... here we go again...
Again, in \renpy\common\00action_menu.py, the developer has created a new function called jackass.
It checks if the console is enabled, switches it off and resets all the player's progress. /sigh.
Thankfully, as far as I can tell, it is only invoked once. So remove the two lines:
Python:
python:
jackass()
Now, back to my original explanation...
It depends.
Mostly upon how much you know about the RenPy console.
If you haven't already, rerun UnRen can select "3) Enable Console and Developer Menu".
That will enable the console and the developer tools.
Because of the way the developer has handled variables (not using default), none of those variables exist until they are first used.
However, once they do - you can press <ALT + D> together to bring up the developer menu and select "Variable Viewer". It will let you know the variable names and their current values. Just use the [RETURN] button when you want to return back to the game.
In addition to <ALT + D>, you can also use <ALT + O> to bring up the RenPy console.
From there you can enter RenPy and/or python commands.
Realistically, you probably only need (up to) 4 commands.
print <variablename>
Shows the value (not much different than the variable viewer).
<variablename> = <value>
Change the value of a variable to any value you like.
watch <variablename>
Add a variable to the "watch list" (a small window in the top right, that will show you the values while you play the game)
unwatch <variablename>
Remove a variable from the watch list.
Examples...
Python:
print mandy_love
mandy_love = 60
watch mandy_love
In addition, the <ESC> key will return you to the game.
This developer is going out of their way to avoid people cheating. Presumably because they intend to add a cheat menu to the phone, for Patreon/Subscribestar members only.
Personally, I would wait for them to add that functionality for them - then wait for the inevitably hack that bypasses the restriction for non-subscriber players.