[SOLVED]A Call Label in A For 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
GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

[SOLVED]A Call Label in A For Loop

#1 Post 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 ?
Last edited by GoldenD on Mon Jan 20, 2020 8:53 am, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: A Call Label in A For Loop

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

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: A Call Label in A For Loop

#3 Post 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
Frameworks & Scriptlets:

GoldenD
Regular
Posts: 43
Joined: Thu Jan 16, 2020 2:01 am
Contact:

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

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

Post Reply

Who is online

Users browsing this forum: No registered users