"random.randint" issue [SOLVED]

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
UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

"random.randint" issue [SOLVED]

#1 Post by UselessCoder »

Hello guys,

I'm trying to randomize the kind of jobs a character can perform according to his career rank.
Apparently tho, every time I level up it only picks the first "task" of the new rank...Then it goes back picking the previous ones, which is so weird.
I don't know what am I doing wrong, any help would be greatly appreciated...

Thanks in advance!

Code: Select all

label work_start:
    if persistent.stats ["CAR"]<10: ### YOU'RE A ROOKIE UNTIL LV. 10
        jump rookie_jobs
    elif persistent.stats ["CAR"]==10: ### INTERMEDIATE RANK UNLOCKS AT CAR LV.10
        jump intermediate_jobs
    elif persistent.stats ["CAR"]==20: ### PRO RANK UNLOCKS AT CAR LV. 20
        jump pro_jobs
        
label rookie_jobs:
    $ rookie_job = renpy.random.randint (1,3)
    if  rookie_job == 1:
        "You solved the case of the vanished A and earned 100 cr!"
        $mod_money (100)
        $persistent.stats ["CAR"]+=1
        jump your_apt
    elif rookie_job == 2:
        "You solved the case of the vanished B and earned 100 cr!"
        $mod_money (100)
        $persistent.stats ["CAR"]+=1
        jump your_apt 
    elif rookie_job == 3:
        "You solved the case of the vanished C and earned 100 cr!"
        $mod_money (100)
        $persistent.stats ["CAR"]+=1
        jump your_apt

label intermediate_jobs:
    $ cop_job = renpy.random.randint (1,3)
    if  cop_job == 1:
        "You guarded some rich guy's A and earned 200 cr!"
        $mod_money (200)
        $persistent.stats ["CAR"]+=1
        jump your_apt
    elif cop_job == 2:
        "You guarded some rich guy's B and earned 200 cr!"
        $mod_money (200)
        $persistent.stats ["CAR"]+=1
        jump your_apt
    elif cop_job == 3:
        "You guarded some rich guy's C and earned 200 cr!"
        $mod_money (200)
        $persistent.stats ["CAR"]+=1
        jump your_apt    

label pro_jobs:
    $ scop_job = renpy.random.randint (1,3)
    if  scop_job == 1:
        "You've ARRESTED some A and earned 300 cr!"
        $mod_money (300)
        $persistent.stats ["CAR"]+=1
        jump your_apt
    elif scop_job == 2:
        "You've ARRESTED some B and earned 300 cr!"
        $mod_money (300)
        $persistent.stats ["CAR"]+=1
        jump your_apt
    elif scop_job == 3:
        "You've ARRESTED some C and earned 300 cr!"
        $mod_money (300)
        $persistent.stats ["CAR"]+=1
        jump your_apt
Last edited by UselessCoder on Thu May 05, 2016 1:49 pm, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: "random.randint" issue

#2 Post by trooper6 »

Look at what you've done logically from top to bottom.

Let's say your Level is 5, what happens?
At label start your check the first condition:
if persistent.stats ["CAR"]<10

This is true, so you jump to rookie_jobs and get a random int and go to that job.

Okay. So far, so good.

Let's say your level is 10, what happens?

At label start your check the first condition:
if persistent.stats ["CAR"]<10
This is not true, so you go to the next condition.
elif persistent.stats ["CAR"]==10

This is true, so you jump to intermediate_jobs and get a random int and go to that job.

Okay. So far, so good.

Now what happens if your level is 15?

At label start your check the first condition:
if persistent.stats ["CAR"]<10
This is not true, so you go to the next condition.
elif persistent.stats ["CAR"]==10
Now, this asks if the level is exactly 10, and it isn't. It is 15. So this is not true. So the program goes to the next condition.
elif persistent.stats ["CAR"]==20
This asks if the level is exactly 20, and it isn't. It is 15. So this is not true either. So the program continues on to the next line of code...which is?

label rookie_jobs

So then it picks a random rookie job and continues on from there.

You want to fix your work_start if/else statements.

Something like:

Code: Select all

label work_start:
    if persistent.stats ["CAR"]<10: ### YOU'RE A ROOKIE UNTIL LV. 10
        jump rookie_jobs
    elif persistent.stats ["CAR"]<20: ### INTERMEDIATE RANK UNLOCKS AT CAR LV.10
        jump intermediate_jobs
    elif persistent.stats ["CAR"]>19: ### PRO RANK UNLOCKS AT CAR LV. 20
        jump pro_jobs
        
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: "random.randint" issue

#3 Post by UselessCoder »

Oh Fffff....udge.
I didn't notice I hadn't set conditions for in-between 10 and 20... :facepalm:
Lesson learned: take some breaks every now and then.

Thank you so much!

Post Reply

Who is online

Users browsing this forum: arewar, Bing [Bot], Google [Bot]