I've spent quite a bit of time scouring the forum for an answer to my question but the more I read the more confused I get. I wonder if someone could possibly write the simplest possible code example for me so I can finally understand.
I want to call a screen and change data on that screen.
I want the data to be saved whether I return to the main game or whether I save & exit from that screen.
I want the data to be saved to include values of variables in instances of my custom classes.
Yours hopefully,
A. Noob
Saving values changed in screens
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.
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.
Re: Saving values changed in screens
I assume you mean having multiple input fields on screen?
I found this in the release notes for 6.99.10: https://www.renpy.org/dev-doc/html/chan ... er-changes
I found this in the release notes for 6.99.10: https://www.renpy.org/dev-doc/html/chan ... er-changes
According to the input values page: https://www.renpy.org/dev-doc/html/scre ... put-valuesThe input widget now accepts input values Input values allow an input to directly update a variable, field, or dict, and also make it possible to have multiple inputs displayed at the same time.
Haven't got code examples as I'm not super familiar with Ren'py yet, but if you struggle to work it out I'm sure someone else here with more experience can show youFieldInputValue(object, field, default=True, returnable=False)
An input value that updates field on object.
field
A string giving the name of the field.
default
If true, this input can be editable by default.
returnable
If true, the value of this input will be returned when the user presses enter.
Re: Saving values changed in screens
Have you seen this - https://www.renpy.org/doc/html/save_load_rollback.html? If not - try, it should help.
Re: Saving values changed in screens
Thanks for responding. Yes I have seen these pages - I've been reading the documentation and this forum and somehow I seem to be fundamentally missing something. A brain? I have done a reasonable amount of programming in different languages and I've managed to make a fair number of games. But somehow I seem to be struggling to get my head around the questions in my original post. So I would be very grateful if some kind soul could post some code that shows how to achieve those tasks in the simplest possible way.
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Saving values changed in screens
Perhaps this may you in your thinking. Screens generally don't hold data, they generally show data. You change the data by changing the data and the screen will reflect those changes.
How do you change the data? You can do it by hand in the script, you can have a button or a slider or whatever.
It is hard to give you code when you are being a bit vague. So could you be more specific?
What sor of screen is it? What data is being shown on the screen (specifically). What sort of changes to the data do you want to make and how do you plan to have those changes take place?
Can you give an actual use case?
Because at its simplest:
I'm on my cell phone, but that code should work. Data is shown and updated on a screen. The variable is saved.
So...could you be clearer on the what you want?
How do you change the data? You can do it by hand in the script, you can have a button or a slider or whatever.
It is hard to give you code when you are being a bit vague. So could you be more specific?
What sor of screen is it? What data is being shown on the screen (specifically). What sort of changes to the data do you want to make and how do you plan to have those changes take place?
Can you give an actual use case?
Because at its simplest:
Code: Select all
default hp = 10
screen stats():
text "HP: [hp]"
label start:
show screen stats
"Game starts."
$hp = 5
"You now have 5 hp, you can see that on the screen."
So...could you be clearer on the what you want?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Saving values changed in screens
More info will definitely help, such as where is this screen launched? What type of changes are you making?
For some reason when I last read your post I thought you wanted multiple inputs (text data), so kind of a form that you feel in before saving - but maybe there're things like bars (value ranges) or toggles that you're thinking about as well. I believe those can be changed instantly using the SetField action.
Multiple input is the one I'm not too sure about.
For some reason when I last read your post I thought you wanted multiple inputs (text data), so kind of a form that you feel in before saving - but maybe there're things like bars (value ranges) or toggles that you're thinking about as well. I believe those can be changed instantly using the SetField action.
Multiple input is the one I'm not too sure about.
Re: Saving values changed in screens
Think I've cracked it. The point "Screens generally don't hold data, they generally show data" put me on the right track. The problem was that I was trying to run python code in the screen without handing control back to Ren'Py so that when I saved only the data changes up to the last Ren'Py command were being saved. I'm including the code I came up with to illustrate my point and also because it may help someone else struggling in a similar way.
The example shows - rather abstractly - player being given two quests each comprising three stages. The conversations with the quest giver are done with normal Ren'Py functionality, the quests are done by clicking a button on the screen which runs python code.
The key point in relation to my initial problem is the while loop. After each button click on the screen, control is given back to Ren'Py and thus data is updated regularly and saving at any point is possible.
Thanks all for help. Any further suggestions for improvement gratefully received.
The example shows - rather abstractly - player being given two quests each comprising three stages. The conversations with the quest giver are done with normal Ren'Py functionality, the quests are done by clicking a button on the screen which runs python code.
The key point in relation to my initial problem is the while loop. After each button click on the screen, control is given back to Ren'Py and thus data is updated regularly and saving at any point is possible.
Thanks all for help. Any further suggestions for improvement gratefully received.
Code: Select all
define q = Character('Quest Giver', color="#c8c8ff")
init python:
class TestClass(object):
def __init__(self):
self.x = 0
def testinstancesdata():
testinstance01.x = 20
testinstance02.x = 30
def btn01click():
testinstance01.x += 1
global testvar01
testvar01 += 1
return
init:
style text_style01 is text:
size 20
color (255,0,0,255)
# The game starts here.
label start:
python:
testinstance01 = TestClass()
testinstance02 = TestClass()
testinstancesdata()
testvar01 = 0
questcount = 0
q "Steal the troll's treasure"
while questcount < 3:
$ questcount += 1
call screen savetest()
q "Steal the dragon's treasure"
$ questcount = 0
while questcount < 3:
$ questcount += 1
call screen savetest()
screen savetest:
text "testvar01: [testvar01]" style "text_style01" xpos 100 ypos 300
text "testinstance01.x: [testinstance01.x]" style "text_style01" xpos 100 ypos 350
text "questcount: [questcount]" style "text_style01" xpos 100 ypos 400
textbutton "btn01click":
xpos 100 ypos 100
action [Function(btn01click),Return()]
Who is online
Users browsing this forum: Li yuanlin