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.
#the source code of save/load archive (part)
## The grid of file slots.
grid gui.file_slot_cols gui.file_slot_rows:
style_prefix "slot"
xalign 0.5
yalign 0.5
spacing gui.slot_spacing
for i in range(gui.file_slot_cols * gui.file_slot_rows):
$ slot = i + 1
button:
action FileAction(slot)
has vbox
add FileScreenshot(slot) xalign 0.5
text FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty slot")):
style "slot_time_text"
text FileSaveName(slot):
style "slot_name_text"
key "save_delete" action FileDelete(slot)
I have a demand :
I want to save some data when i go to archive!(the data and the archive are one-to-one correspondence)
of course ,when I want to load the archive, I would like to load the data corresponding to this archive。
So, I need the name of archive,then let the name be the key of my data
I defined an customFileAction method instead of the FileAction method
def FileAction(name, page=None, **kwargs):
"""
:doc: file_action
"Does the right thing" with the file. This means loading it if the
load screen is showing (current screen is named "load"), and saving
otherwise.
`name`
The name of the slot to save to or load from. If None, an unused slot
(a large number based on the current time) will be used.
`page`
The page that the file will be saved to or loaded from. If None, the
current page is used.
Other keyword arguments are passed to FileLoad or FileSave.
"""
if renpy.current_screen().screen_name[0] == "load":
return FileLoad(name, page=page, **kwargs)
else:
return FileSave(name, page=page, **kwargs)
class FileLoad .......
class FileSave ......
# 存档读档 获取id
def coustomFileAction(name):
return AttributeSave(name)
class AttributeSave(object):
def __init__(self,name):
self.name = name
self.fileAction = FileAction(name)
def __call__(self):
#保存一个数据
# TODO save my data with self.name
self.fileAction()
#layout.yesno_screen(str(self.name), None,None)
init python:
def jsondata(charadata): #charadata is the name of the dictionary you have to check in the slot screen
#now register values into the dictionary
charadata["points"]=score
config.save_json_callbacks.append(jsondata) #append the function before each save action
2 - retrieve the data in the slot screen, like this:
init python:
def jsondata(charadata): #charadata is the name of the dictionary you have to check in the slot screen
#now register values into the dictionary
charadata["points"]=score
config.save_json_callbacks.append(jsondata) #append the function before each save action
2 - retrieve the data in the slot screen, like this:
# Display ten file slots, numbered 1 - 10.
for i in range(1, columns * rows + 1):
# Each file slot is a button.
button:
action FileAction(i)
xfill True
In python, you use an iterator in the for... cycles.
In this case, the iterator is "i" and go from 1 to columns * rows + 1.
Each step of the cycle, i increase by 1.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
# Display ten file slots, numbered 1 - 10.
for i in range(1, columns * rows + 1):
# Each file slot is a button.
button:
action FileAction(i)
xfill True
In python, you use an iterator in the for... cycles.
In this case, the iterator is "i" and go from 1 to columns * rows + 1.
Each step of the cycle, i increase by 1.