random dialogue renpy

Cohibozz

Member
Aug 14, 2018
125
27
i'm thinking to set my game like free roaming with a random dialogue with some condition:
ie: rel and lust under 10 with bschar :

if location is kitchen and lust < 5 :
random dialogue fronm 10 different


something like. this....
Code:
$ randdiag0 = True
$ randdiag1 = True
$ randdiag2 = True
$ randdiag3 = True
$ randdiag4 = True
$ randdiag5 = True
$ randdiag6 = True
$ randdiag7 = True
$ randdiag8 = True
$ randdiag9 = True
$ randdiag10 = True
$count = 0
label bs_0_10:
    $randdiag = renpy.random.randint(0,10)
    if count <= 10 :
        if (0 <= bslust <= 10) or (0 <= bsrel <= 10):
            if randdiag == 0 and randdiag0 == True :
                menu:
                    blablabla
                    $randiag0 = False
                    $count += 1
                else:
                    action Call ("bs_0_10")
      
            if randdiag == 1 and randdiag1 == True :
                menu:
                    blablabla
                    $randiag1 = False
                    $count += 1
                else:
                    action Call ("bs_0_10")

        ..................
        .....................
    else:
        #some menu without random here

my idea is good? how can i call the menu? with a simply -> Call bs_0_10 ??
 

Cohibozz

Member
Aug 14, 2018
125
27
if it's ok a can add also a condition for location in menu. so i can add 10 o more different dialogue in any location.
i can also add other variables for some menu....as car keys .....if i've found the car keys after randomly a dialogue for the car can append!...
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,263
15,073
my idea is good? how can i call the menu? with a simply -> Call bs_0_10 ??
The idea is good, the code less ; but well, you wouldn't be asking if you already knew.


Code:
$ randdiag0 = True
$ randdiag1 = True
$ randdiag2 = True
$ randdiag3 = True
$ randdiag4 = True
$ randdiag5 = True
$ randdiag6 = True
$ randdiag7 = True
$ randdiag8 = True
$ randdiag9 = True
$ randdiag10 = True
This kind of things always remember me of school, when I was punished and had to write so many times the same sentence. What have you done to be punished by Ren'py ? :D
More seriously, there's array ; well, Python call them "list" but it's the same. They come with many advantages.


Firstly, one line is enough to declare all your flags :
Code:
$ randDiagArray = [ True for i in range(0, 11) ]
It will create a 11 rows list and fill the said rows with True.
Note: range stop right before the last value, so it will create the rows 0 to 10.

Secondly, one line is enough for all the condition tests :
Code:
            if randDiagArray[randdiag] == True :
Thirdly, because otherwise it would be useless, one line is really enough for all the condition tests :
Code:
            if randDiagArray[randdiag] == True :
                 call expression "randDiagMenu{}".format( randdiag )
Note: "action Call" is a screen language thing, you aren't in a screen here. Just use call. The added "expression" mean that Ren'py will build the label, by evaluating the Python expression that follow.


In the end, your code will looks like this :
Code:
# create the array and make it savable from start
default randDiagArray = [ True for i in range(0, 11) ]
# same for the counter
default count = 0

label bs_0_10: 

    # Note: unlike /range/, /randint/ include the last value.
    $ randdiag = renpy.random.randint(0,10)
    if count <= 10:
        if (0 <= bslust <= 10) or (0 <= bsrel <= 10):
            if randDiagArray[randdiag] == True :
                 call expression "randDiagMenu{}".format( randdiag )
                 $ randDiagArray[randdiag] = False
                 $ count += 1
           else:
                 # Do NOT call everywhere, especially yourself.
                 jump bs_0_10
# There were a missing else somewhere
         else: # bslut or bsrel not between 0 and 10
            # something
    else: # count > 10
        $ count = 0
        #some menu without random here

# chose only one
    return # if you called the label
    jump somewhereElse # if you jumped to the label

label randDiagMenu0:
    [...]
    return  # You called it, so return to the calling code

label randDiagMenu1:
    [...]
    return

[...]

label randDiagMenu10:
    [...]
    return
Note that if you really intend to have pure menu, you can also write this :
Code:
menu randDiagMenu0:
    "some choice":
         [...]
         return
    "some other choice":
         [...]
         return
 

Cohibozz

Member
Aug 14, 2018
125
27
Ty! Mine was only an example to what I wanna do. Your code is good! I be to try it as soon possible. Ty a lot for all help u give me!