Page 1 of 1

[SOLVED]A Call Label in A For Loop

Posted: Mon Jan 20, 2020 4:32 am
by GoldenD
Hi guys,

a new easy challenge for you i'm sure.


First, I define a Python Tuple (because i like its static format) :

Code: Select all

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 :

Code: Select all

# 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.

Code: Select all


# 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..."


    return      #WITH OR WITHOUT NO CHANGE

Like always, an idea, a dream, a cup of tea ?

Re: A Call Label in A For Loop

Posted: Mon Jan 20, 2020 7:13 am
by gas
I don't see the point when you can use a 'call expression' instead of using python equivalents.
Anyway, the call statement push the NEXT statement in the return stack (for obvious reasons), so probably the iterator method isn't just called again after the first iteration.
You can try a while: statement in a python: block (I can't test it right now, but could work) but more probably you can fake a loop by using labels.

label myloop:
# updating the variable
# call expression the label you want
label loop_break:
# on conditional, jump back to myloop or proceed.

Re: A Call Label in A For Loop

Posted: Mon Jan 20, 2020 8:08 am
by Remix
As gas alludes to, Ren'Py cannot return from a call into the middle of a python loop or block, it returns to the point after it (actually the point before it then steps forward)

I would advise trying to keep all your game progression inside label code (as this works well with rollback and saving systems)

You can use while loops in labels:

Code: Select all


define dlgTupleDouble = (
    ("pictureOne.jpg",  "First Speaker talk"),
    ("pictureTwo.jpg",  "Second Speaker talk"),
    ("pictureThree.jpg","Third Speaker talk"))

label dlg_loop:

    "Before Loop"

    $ dlg_count = 0
    while dlg_count < len(dlgTupleDouble):

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

        $ dlg_count += 1

    "After Loop"

    return

label dlg_talk(pic, speech):

    "[pic!q] with [speech!q]"

    return

[SOLVED]Re: A Call Label in A For Loop

Posted: Mon Jan 20, 2020 8:51 am
by GoldenD
Remix wrote:
Mon Jan 20, 2020 8:08 am
As gas alludes to, Ren'Py cannot return from a call into the middle of a python loop or block, it returns to the point after it (actually the point before it then steps forward)

I would advise trying to keep all your game progression inside label code (as this works well with rollback and saving systems)

You can use while loops in labels:

Code: Select all


define dlgTupleDouble = (
    ("pictureOne.jpg",  "First Speaker talk"),
    ("pictureTwo.jpg",  "Second Speaker talk"),
    ("pictureThree.jpg","Third Speaker talk"))

label dlg_loop:

    "Before Loop"

    $ dlg_count = 0
    while dlg_count < len(dlgTupleDouble):

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

        $ dlg_count += 1

    "After Loop"

    return

label dlg_talk(pic, speech):

    "[pic!q] with [speech!q]"

    return
Ok guys,
I was actually reading some indigestible stuff about __iter__, __next___...methods.
So, your solution is working, that's great and i notice and understand your advise about
keep all your game progression inside label
.
Thanks a lot.