Ren'Py [SOLVED]A Call Label in A For Loop

GoldenD

Member
Sep 30, 2018
102
70
Hi guys,
a new easy challenge for you i'm sure.

First, I define a Python Tuple (because i like its static format) :
Python:
define dlgTupleDouble = (
("pictureOne.jpg",  "First Speaker talk"),
("pictureTwo.jpg",  "Second Speaker talk"),
("pictureThree.jpg","Third Speaker talk")
)
Second, I want to display all datas from this tuple.
This first way is OK :
Python:
# Direct display in for loop    =>  OK (display the 3 records)

    python :
        for idTalk, valueTalk in dlgTupleDouble:
            idSpeaker = idTalk
            renpy.say(idSpeaker, valueTalk)
This second way doesn't work. Only the first record is display and pgm is ending.
Python:
# Using a label DisplayScene    => BAD (display the first and finish)

    python :
        for idTalk, valueTalk in dlgTupleDouble:
            renpy.call("displayScene", idTalk, valueTalk)


label displayScene(idTalker="", dlgScene=""):

    if idTalker != "":
        $ idSpeaker = idTalker
        idSpeaker "[dlgScene]"
    else:
        "No speach..."                    # Never execute

    return      #WITH OR WITHOUT NO CHANGE
Like always, an idea, a dream, a cup of tea ?
 
Last edited:

GoldenD

Member
Sep 30, 2018
102
70
Hi guys,
a new easy challenge for you i'm sure.

First, I define a Python Tuple (because i like its static format) :
Python:
define dlgTupleDouble = (
("pictureOne.jpg",  "First Speaker talk"),
("pictureTwo.jpg",  "Second Speaker talk"),
("pictureThree.jpg","Third Speaker talk")
)
Second, I want to display all datas from this tuple.
This first way is OK :
Python:
# Direct display in for loop    =>  OK (display the 3 records)

    python :
        for idTalk, valueTalk in dlgTupleDouble:
            idSpeaker = idTalk
            renpy.say(idSpeaker, valueTalk)
This second way doesn't work. Only the first record is display and pgm is ending.
Python:
# Using a label DisplayScene    => BAD (display the first and finish)

    python :
        for idTalk, valueTalk in dlgTupleDouble:
            renpy.call("displayScene", idTalk, valueTalk)


label displayScene(idTalker="", dlgScene=""):

    if idTalker != "":
        $ idSpeaker = idTalker
        idSpeaker "[dlgScene]"
    else:
        "No speach..."                    # Never execute

    return      #WITH OR WITHOUT NO CHANGE
Like always, an idea, a dream, a cup of tea ?

Ok, the solution is here without "for" because __iter__.
For information :
Python:
                $ dlg_count = 0
                while dlg_count < len(dlgTupleDouble):

                    call displayScene(*dlgTupleDouble[dlg_count])
                    # the * just passed in the list as separate arguments

                    $ dlg_count += 1
Thanks.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,355
15,268
Second, I want to display all datas from this tuple.
Either you do it directly where you are :
Python:
define mc = Character( "the mc" )
define girl = Character( "the girl" )

define dynDialog = [ ( "blablabla", mc ), ( "bliblibli", girl ) ]

label whatever:
    $ i = 0
    while i < len( dynDialog ):
        if isinstance( dynDialog[i][1], renpy.character.ADVCharacter ):
            $ dynDialog[i][1]( dynDialog[i][0] )
        $ i += 1
Or you directly pass the list :
Python:
define mc = Character( "the mc" )
define girl = Character( "the girl" )

define dynDialog = [ ( "blablabla", mc ), ( "bliblibli", girl ) ]

label whatever:
    call displayScene( dynDialog )
#    call displayScene( [ ( "blablabla", mc ), ( "bliblibli", girl ) ] )

label displayScene( dials ):
    $ i = 0
    while i < len( dials ):
        if isinstance( dials[i][1], renpy.character.ADVCharacter ):
            $ dials[i][1]( dials[i][0] )
        $ i += 1      
    return
But making the loop call the display label is overkill.

There's also something I don't understand. You want to simulate a dynamic dialog, but in your example it's not dialog line that you assign to the list, but name of images :/


This second way doesn't work. Only the first record is display and pgm is ending.
Because, like the call statement, renpy.call will return to next Ren'py statement, not to the next Python statement. Therefore, Ren'py break out of the loop once it perform the first call.
 

GoldenD

Member
Sep 30, 2018
102
70
Holà AON,

this explanation

Because, like the call statement, renpy.call will return to next Ren'py statement, not to the next Python statement. Therefore, Ren'py break out of the loop once it perform the first call.
is simplest than i thought, thanks.


There's also something I don't understand. You want to simulate a dynamic dialog, but in your example it's not dialog line that you assign to the list, but name of images :/
Like I said, i assign this tuple (list)
Python:
define dlgTupleDouble = (
("pictureOne.jpg",  "First Speaker talk"),
("pictureTwo.jpg",  "Second Speaker talk"),
("pictureThree.jpg","Third Speaker talk")
)
with picture as first arg, and dialog as second. In fact i've more args to assign but the concept is the same.

And thanks too for your sample assigning a list, that's what i'll have to do.