Ren'Py [SOLVED] for loop not working like I want

Noldem

New Member
Aug 6, 2017
7
2
Hello everyone, first let me say I'm sorry for my english and if this question is stupid.

I've been struggling for a long time because one of my for loop doesn't loop at all. I have to say that it's my first time coding with renpy so yes my code may be ugly. Sorry about that.

so here's my code :

Code:
python:
    for i in range(1, 3):
        renpy.say(m, "attacks!")
        renpy.call("qte_setup", 0.5, 0.5, 0.01, renpy.random.choice(arr_keys), renpy.random.randint(1, 9) * 0.1, renpy.random.randint(1, 9) * 0.1)
            if cont == 1:
                renpy.say(m, "Hit!")
                if(i == 1):
                    ennemy1.curHP -= h.atk
                if(i == 2):
                    ennemy2.curHP -= h.atk
            else:
                renpy.say(m, "Miss...")
The qte_setup is in the attached file. I took this code on a tutorial I found. Although not everything is clear in my head, I don't think that the problem comes from this qte file. Is it a problem because of the renpy.call I use?
Thank for your help in advance.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,284
I've been struggling for a long time because one of my for loop doesn't loop at all.
[...]
Code:
[...]
        renpy.call("qte_setup", [...])
[...]
Boom.
Both jump and call statements, and their Python equivalent, interrupt the flow and branch you outside of it. call know how to return back, but at statement level, not at Python level. This mean that your code could never works as it is.

If really you want to loop, either you don't use an intermediary label:
Code:
python:
    for i in range(1, 3):
        renpy.say(m, "attacks!")
        renpy.call_screen("qte_simple", 0.5, 0.5, 0.01, renpy.random.choice(arr_keys), renpy.random.randint(1, 9) * 0.1, renpy.random.randint(1, 9) * 0.1)
        if _return == 1:
[...]

screen qte_simple(time_start, time_max, interval, trigger_key, x_align, y_align):
[...]
or you do it purely in Ren'Py language:
Python:
label whatever:
    $ loop = 2    # You know that you're looping only twice, right ?
    while loop > 0:
        m "attacks!"
        call qte_setup( 0.5, 0.5, 0.01, renpy.random.choice(arr_keys), renpy.random.randint(1, 9) * 0.1, renpy.random.randint(1, 9) * 0.1)
        if _return == 1:
            m "Hit!"
            if i == 1:
                $ ennemy1.curHP -= h.atk
            if i == 2:
                $ ennemy2.curHP -= h.atk
            else:
                m "Miss..."
        $ loop -= 1
[...]
Third solution, that need advanced knowledge, you create a user defined statement to add for into Ren'Py language.
 
  • Like
Reactions: Noldem

Noldem

New Member
Aug 6, 2017
7
2
Oh I see, thank you very much.
And yes I know i'm looping only twice, it was just for testing. It will normally loop depending on the number of ennemies. Damn it's so logic that now I feel dumb. Anyway, thank you again.