[solved] menus with a loop

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.
Post Reply
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved] menus with a loop

#1 Post by Kia »

today this crazy idea crossed my mind: what if I generate the menus with a loop?
it sure would help with the animation when I have to calculate the values I'm passing to each button depending on their order in the menu.
I've wrote something that I thought might work:

Code: Select all

default menuz = [["Start",'Start()'],["Load",'ShowMenu("load")']]

screen main_menu():
    tag menu
    style_prefix "mm"
    hbox:
        for i in range(2):
            button:
                text menuz[i][0]
                action menuz[i][1]
but it seems that there is a little problem with passing the actions as a variable:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
TypeError: 'unicode' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\ast.py", line 848, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\python.py", line 1812, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in <module>
    ui.interact()
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\core.py", line 2624, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\core.py", line 3417, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\layout.py", line 986, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\layout.py", line 986, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\layout.py", line 986, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\screen.py", line 667, in event
    rv = self.child.event(ev, x, y, st)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\layout.py", line 986, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\layout.py", line 986, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\behavior.py", line 897, in event
    return handle_click(self.clicked)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\behavior.py", line 832, in handle_click
    rv = run(action)
  File "D:\gamedev\renpy-6.99.14.1-sdk\renpy\display\behavior.py", line 306, in run
    return action(*args, **kwargs)
TypeError: 'unicode' object is not callable

Windows-7-6.1.7601-SP1
Ren'Py 6.99.14.1.3218
menu on loop 1.0
Sat Apr 14 22:26:06 2018
anyone got any idea what's going on and how to get it done?
of curse I need to figure out solutions to more problems like how to translate them but for now, one step at a time.
Last edited by Kia on Sun Apr 15, 2018 5:18 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2397
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: menus with a loop

#2 Post by Ocelot »

Try to follow what happens when code is executed.
Right now it creates following button:

Code: Select all

button:
    text "Start"
    action 'Start()'
See the problem?
< < insert Rick Cook quote here > >

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: menus with a loop

#3 Post by Kia »

Ocelot wrote: Sun Apr 15, 2018 3:14 am Try to follow what happens when code is executed.
See the problem?
of curse, my problem is how to store the buttons action in a list, other than storing it as a string, I can't think of any other way

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: menus with a loop

#4 Post by IrinaLazareva »

Code: Select all

default menuz = [["Start", Start()], ["Load", ShowMenu("load")]]

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: menus with a loop

#5 Post by Kia »

IrinaLazareva wrote: Sun Apr 15, 2018 4:48 am

Code: Select all

default menuz = [["Start", Start()], ["Load", ShowMenu("load")]]
I can't believe I missed that, I actually tried it like that at first but I must've misplaces a symbol somewhere :oops:
thanks ^_^

Post Reply

Who is online

Users browsing this forum: No registered users