Global Variable and Renpy function in Init Python? (Solved)
Posted: Tue Oct 09, 2018 10:37 pm
Struggling to understand what's happening with my code, hopefully someone can shed some light? ^^;
This is what I started with, and closest to my intentions. I'm trying to generate a bunch of variables based on two input values to the function. At first, without the global value code, the code wasn't working at all. After putting in the code, it returns monlvl = 8 and monhp = 80, seemingly to completely ignore the if statements?? Is it because I'm trying to use a renpy function within init python?
within label start:
This is where I'm currently up to in terms of trying to troubleshoot? I noticed that the renpy random function was working sometimes. At one point it spit out a negative number. Then at another point, the return was monhp = 40 and monlvl = 5, which seems impossible?? Also, although I run the function twice to check how random the generator is, I always get the exact same values both times.
within label start:
Thank you in advance ^^
This is what I started with, and closest to my intentions. I'm trying to generate a bunch of variables based on two input values to the function. At first, without the global value code, the code wasn't working at all. After putting in the code, it returns monlvl = 8 and monhp = 80, seemingly to completely ignore the if statements?? Is it because I'm trying to use a renpy function within init python?
Code: Select all
init python:
monlvl = 8
def mgen1(x, lvl):
global monlvl
if lvl > 3:
monlvl = renpy.random.randint((lvl-3),lvl)
elif lvl == 3:
monlvl = renpy.random.randint(1, 3)
elif lvl == 2:
monlvl = renpy.random.randint(1, 2)
elif lvl == 1:
monlvl = 1
if x == 1:
monhp = monlvl*10
else:
pass
return monlvl, monhp
Code: Select all
"Text"
$ mclvl = 5
init python:
monlvl, monhp = mgen1(1, mclvl)
"mclvl is [mclvl]"
"monhp is [monhp]"
"monlvl is [monlvl]"
init python:
monlvl, monhp = mgen1(1, mclvl)
"monhp is [monhp]"
"monlvl is [monlvl]"
Code: Select all
init python:
monlvl = 8
def mgen1(x, lvl):
global monlvl
monlvl = renpy.random.randint(2,6)
if x == 1:
monhp = monlvl*10
else:
pass
return monlvl, monhp
Code: Select all
"Text"
$ mclvl = 5
init python:
monlvl, monhp = mgen1(1, mclvl)
"mclvl is [mclvl]"
"monhp is [monhp]"
"monlvl is [monlvl]"
init python:
monlvl1, monhp1 = mgen1(1, mclvl)
"mclvl is [mclvl]"
"monhp1 is [monhp]"
"monlvl1 is [monlvl]"