Code: Select all
# to call a location with a button on the screen screen, # need to call it in a new context. # i.e. another game opens up. # and hide all previous screens. # that's just when you save the game, only the place is remembered, # from where the first call was called, as if all the return had already worked # therefore, saving is better to disable #Total: the method works only for all sorts of menus, # but not for branching plot init python: # stack for storing state of screens until call screens =  # action by ESC button gamemenu = config.game_menu_action # add a regular list of screens def s_push (item): global screens screens.append (item) # get the latest list of screens def s_pop (): global screens if len (screens)> 0: return screens.pop () return  # starting amount of money for testing money = 10 # flag calling location in new context is_call = False # from the screen can not perform the usual call label # create an analog class MyCall (Action): def __init __ (self, label, * args, ** kwargs): self.label = label self.args = args self.kwargs = kwargs def __call __ (self): global screens, is_call # disable ESC config.game_menu_action = NullAction () # remember screens s_push (renpy.current_screen (). screen_name) # turn on the call flag of the new context (to hide the button) is_call = true # call location in new context renpy.call_in_new_context (self.label, * self.args, ** self.kwargs) # function to restore screens in new context def show_screens (): for i in screens [-1:]: renpy.show_screen (i) # function to return from location in new context def myreturn (): global is_call # hide screens for i in s_pop (): renpy.hide_screen (i) # uncheck the flag of the new location so that its call button appears again is_call = len (screens)> 0 if not is_call: config.game_menu_action = gamemenu # save game data renpy.retain_after_load () Return () () # so that you can bind to digging, for example MyReturn = renpy.curry (myreturn) # screen from which you can call screen test: text _ (str (money) + "money") align (.05, .05) # button is shown only if the call is not executed by pressing it if not is_call: # button that performs analog call label textbutton _ ("Cheat") align (.95, .05) action MyCall ("menu1") else: # call a call from a label that is already called using call textbutton _ ("hint") align (.95, .05) action MyCall ("hnt") label start: show expression "images / bg.jpg" show screen test "You have created a new Ren'Py game." "Add a plot, images and music and send it to the world!" return # another location from which you can return to the same place of the game # if you wish, you can pass parameters when calling # then you can call it like this: ... action MyCall ("menu1", plus = 100) label menu1 (plus = 10): # display all screens hidden when calling a location in a new context $ show_screens () # Actually some actions $ loop1 = true # we loop before pressing the 3rd button while loop1: menu: "+ [plus]": $ money + = plus "- [plus]": $ money - = plus "Return": $ loop1 = False # go back to where you came from, restoring the old state of affairs # instead of return $ MyReturn () () return label hnt: scene black centered "Hint: This is a nested call from another call." $ MyReturn () () return
Download the finished sample.
http://renpyfordummies.blogspot.com/201 ... n.html?m=1