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.
-
BigBucket
- Regular
- Posts: 26
- Joined: Wed Aug 21, 2019 9:19 pm
-
Contact:
#1
Post
by BigBucket » Tue Oct 20, 2020 3:46 pm
I'm using a variable to determine what will show in a phone chat. The way it works is that there's a Vbox and things show up based on the variable value, which is incremented by 1 everytime you click on the screen outside of the chat.
I'm declaring my variable in the script file, before anything else, at the top of the file as:
Then this is the way it's incremented:
Code: Select all
key "dismiss" action [(SetVariable ("var_chat", var_chat+1))]
It does increment and stuff show up on the Vbox, but everytime I load the save file or close the game, the variable is set back to 0.
What am I doing wrong?
EDIT: I'm using this variable inside a screen and not through labels.
-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#2
Post
by Remix » Tue Oct 20, 2020 4:17 pm
So, you start a new game and the value is 0 (as expected)
You load a save and the value is 0 (we'd expect it to retain the value it was when the save was done, so this is possibly expected too). You've not confirmed the save holds a different value so we do not know.
If you wanted it to maintain state between different play throughs, make it persistent. Pretty sure you do not want that though. I'd search your entire script(s) for var_chat and check you are not altering it elsewhere... Other than that, expected behaviour...
-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#3
Post
by Remix » Tue Oct 20, 2020 4:21 pm
Note though that saving from a screen area (without an interaction) will not automatically update the variables value... Ren'Py only natively puts checkpoints at places in label flow that cause interactions... Perhaps close the screen, add a dialogue line and try saving after that is reached.
-
BigBucket
- Regular
- Posts: 26
- Joined: Wed Aug 21, 2019 9:19 pm
-
Contact:
#4
Post
by BigBucket » Tue Oct 20, 2020 4:25 pm
Hmm, it might be the problem with checkpoints then. Will try it.
And yes, I'm making it go up and saving and then closing but it's not saving the final value, but it might be the checkpoint thing. Any dialogue would do it?
-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#5
Post
by Remix » Tue Oct 20, 2020 5:58 pm
Even a pause 0.01 should do it, so if you have no other logical way around it you could theoretically call a label that incremented the variable, paused minutely and returned...
(note that progression through labels should control game progression, not progression through screens... screens should really be for displaying things, not to control game progress)
-
rayminator
- Miko-Class Veteran
- Posts: 754
- Joined: Fri Feb 09, 2018 12:05 am
- Location: Canada
-
Contact:
#6
Post
by rayminator » Wed Oct 21, 2020 11:27 am
you can use this if everything you tried and didn't work
-
SypherZent
- Veteran
- Posts: 331
- Joined: Fri Sep 02, 2016 3:14 am
- Completed: Multiverse Heroes, Space Hamster in Turmoil
- Soundcloud: Chrysopoeist
- Location: Puerto Rico
-
Contact:
#7
Post
by SypherZent » Wed Oct 21, 2020 11:36 am
Are you using 'show' for the screen, or 'call'?
If you use 'call' then you're passing the control to the screen and eventually you need to use the Screen Action called Return() to go back to the labels. Until Ren'Py hits the next label in the script, the variables won't save. If you use 'call' then perhaps rayminator's suggestion may help.
The way I force save when my game is fully based on screens, is to use 'Return' after the statement, then call the screen again from a centric label that I name 'continue_gameplay'. So the flow goes like this:
1) call screen
2) From screen, do action and Return()
3) in the lines after 'call screen' in the script, I put 'jump continue_gameplay'
4) I define label continue_gameplay to call the appropriate screen based on variable setting
Every time the label is visited, Ren'Py internally saves the data, even if you're always jumping to the same label.
Hope this helps.
-
BigBucket
- Regular
- Posts: 26
- Joined: Wed Aug 21, 2019 9:19 pm
-
Contact:
#8
Post
by BigBucket » Thu Oct 22, 2020 8:12 pm
Thank you all for the information. I understood how it works and why it wasn't saving.
I tried incrementing the variable through labels with this code
Code: Select all
label mica_chat_1:
call screen chat
$ var_chat +=1
$ var_chat +=1
$ var_chat +=1
$ var_chat +=1
$ var_chat +=1
$ var_chat +=1
menu:
"Send Picture":
$mica_send_choice_1 = True
"Don't send":
jump chat_screen
and with "pause" between every increment but both ways just kept incrementing with every click infinitely ,instead of just 6 times, and the menu never showed up.
I know this isn't the topic main subject but if it's a simple fix could anyone explain what I should do?
-
rayminator
- Miko-Class Veteran
- Posts: 754
- Joined: Fri Feb 09, 2018 12:05 am
- Location: Canada
-
Contact:
#9
Post
by rayminator » Thu Oct 22, 2020 8:21 pm
how are you returning from the call are you hiding the screen chat when you close or return?
try using hide screen chat under call screen chat
-
PyTom
- Ren'Py Creator
- Posts: 15893
- 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:
#10
Post
by PyTom » Thu Oct 22, 2020 11:30 pm
Code: Select all
key "dismiss" action [(SetVariable ("var_chat", var_chat+1))]
I'd be a little shocked if this ever ran. Generally, the SayBehavior - which is what handles the dismiss key - will terminate the interaction before the screen processes this. As a result, SetVariable will never be called, and so var_chat will not increment.
I'd suggest using a character callback for this, perhaps something like:
Code: Select all
init python:
def bump_var_chat(event, interact=True, **kwargs):
global var_chat
if not interact:
return
if event == "end":
var_chat += 1
config.all_character_callbacks.append(bump_var_chat)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama •
https://www.patreon.com/renpytom
Users browsing this forum: Bing [Bot], Google [Bot]