random choice issues! //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
User avatar
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

random choice issues! //solved

#1 Post by lovebby »

Okay so I've been working on this battle system thing, and I've just kept running into one problem after another. I've got it working alright now, but I can't seem to figure this part out.

Code: Select all

label playerhit:    
                if player == "akreena":
                    $ normal= renpy.random.choice (['2', '3'])
                    if normal == 2:
                        $ enemyHP -=2
                    if normal == "3":
                        $ enemyHP -=3
                    $ critical = renpy.random.choice (['5', '4'])    
                    if critical == "4": 
                        $ enemyHP -=4
                    if critical == "5":
                        $ enemyHP -=5            
                if player == "kotollo":
                    $ normal= renpy.random.choice (['2', '3',])
                    if normal == "2":
                        $ enemyHP -=2
                    if normal == "3":
                        $ enemyHP -=3
                    $ critical = renpy.random.choice (['4', '5',])        
                    if critical == "4": 
                        $ enemyHP -=4
                    if critical == "5":
                        $ enemyHP -=5
                return
If the choices are 2 or 3, renpy will bring up a number of 7, and I don't know how's it getting that?
I have a few other blocks defined like this all doing the same thing.
And is there another method to define "normal"? Like something $enemyHP -= "normal" or do I have to define everything like I just did?
Last edited by lovebby on Mon Apr 14, 2014 8:43 pm, edited 1 time in total.

User avatar
Stapper
Regular
Posts: 96
Joined: Wed Feb 27, 2013 9:54 pm
Contact:

Re: random choice issues!

#2 Post by Stapper »

Get rid of the '
I think it's just reading an old normal variable stored which happens to be 7.

You should also be able to use the stored data there without checking yes, try this:

Code: Select all

                if player == "akreena":
                    $ normal = renpy.random.choice([2, 3])
                    $ enemyHP -= normal
                    $ critical = renpy.random.choice([5, 4])    
                    $ enemyHP -= critical

User avatar
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

Re: random choice issues!

#3 Post by lovebby »

How odd, I was pretty sure I tried that code before, but it didn't go right. Thanks! It works now, but it's still getting the higher numbers. I never even used anything above 5 when testing either, and I've deleted persistent data and all.

User avatar
Stapper
Regular
Posts: 96
Joined: Wed Feb 27, 2013 9:54 pm
Contact:

Re: random choice issues!

#4 Post by Stapper »

No offense but isn't the number you are referring to the total amount? (Just checking) The normal 3 + the critical 4? so that a total amount of 7hp is subtracted?

Or try debugging the code by commenting the normal part out first and running it, then after comment out the critical and see if it has the proper amount? This way you can see where the error lies.

User avatar
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

Re: random choice issues!

#5 Post by lovebby »

Oh god, that was it aha. I just wasn't thinking with that layout, thank you so much!

Post Reply

Who is online

Users browsing this forum: apocolocyntose, Google [Bot], Semrush [Bot]