Problem simulating the dice system

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
blueeyes1345
Regular
Posts: 42
Joined: Thu Mar 19, 2009 11:06 am
Projects: Short School Dating Sims Game
Organization: Emyth Zandra
Location: Singapore
Contact:

Problem simulating the dice system

#1 Post by blueeyes1345 »

hi

i had abit of problems simulating the die system, renpy.random.randint(1,20)

everytime i reach tis part, i keep getting this error.

Code: Select all

Exception: Syntax error on line 67 of /Users/student/Desktop/renpy-6.9.3/Testing/Battle Royale/game/script.rpy:
    renpy.random.randint(1,20) = 1
This is my script

Code: Select all

# You can place the script of your game in this file.

init:
    # Declare images below this line, using the image statement.
    # eg. image eileen happy = "eileen_happy.png"

    # The variable we store the entered name of the character in.
    $ povname = ""
    $ pov1name = ""
    $ pov2name = ""
    $ pov3name = ""
    $ pov4name = ""
    $ pov5name = ""
    $ pov6name = ""
    $ pov7name = ""
    $ pov8name = ""
    $ pov9name = ""

    # And this is a DynamicCharacter that has the same stored in
    # povname.
    $ pov = DynamicCharacter("povname", color=(192, 64, 64, 255))
    $ pov1 = DynamicCharacter("pov1name", color=(192, 64, 64, 255))
    $ pov2 = DynamicCharacter("pov2name", color=(192, 64, 64, 255))
    $ pov3 = DynamicCharacter("pov3name", color=(192, 64, 64, 255))
    $ pov4 = DynamicCharacter("pov4name", color=(192, 64, 64, 255))
    $ pov5 = DynamicCharacter("pov5name", color=(192, 64, 64, 255))
    $ pov6 = DynamicCharacter("pov6name", color=(192, 64, 64, 255))
    $ pov7 = DynamicCharacter("pov7name", color=(192, 64, 64, 255))
    $ pov8 = DynamicCharacter("pov8name", color=(192, 64, 64, 255))
    $ pov9 = DynamicCharacter("pov9name", color=(192, 64, 64, 255))

# The game starts here.
label start:
    
    "Your friends and you have been planned in a sadistic game whether you are stranded on an island and you must kill each other till there is one survivor (winner \o/) ."
    "There is a limit of 3 days whereby if more than one person is alive till then, the locked collars around your necks will blow up."
    "For more plot details, go wiki Battle Royale... meh."
    "P.S. Treat this like a caged match... If you plan to go against the game masters be reminded they are trained military people with the high tech stuff that controls those little bomb collars around your neck."
    "Collars can spy on your conversations and detect your location and your pulse."
    "Have fun~"
    
    $ povname = renpy.input("First Insert your name")
    
    "Hi %(povname)s."
    
    "Next enter the names of your dear friends who are gonna play this game with you"
    "(of cos, choose people who u dun mind killing off ~ *cough* I mean, hmm, dearest to you)"
    
    $ pov1name = renpy.input("Name of your first friend")
    $ pov2name = renpy.input("Name of your 2nd friend")
    $ pov3name = renpy.input("Name of your 3rd friend")
    $ pov4name = renpy.input("Name of your 4th friend")
    $ pov5name = renpy.input("Name of your 5th friend")
    $ pov6name = renpy.input("Name of your 6th friend")
    $ pov7name = renpy.input("Name of your 7th friend")
    $ pov8name = renpy.input("Name of your 8th friend")
    $ pov9name = renpy.input("Name of your 9th friend")
    
    jump nvlmode
    
label ContinueStory01:
    
    "Next, you were given an weapon/item to take along. How you use it is up to you to decide."
    
    menu:
        "Choose Weapon":
            if renpy.random.randint(1,20) = 1:
                "Congratulations, you just got yourself a..."
                jump weaponPaperfan
                
            if renpy.random.randint(1,20) = 2:
                "Congratulations, you just got yourself a..."
                jump weaponShotGun
                
            if renpy.random.randint(1,20) = 3:
                "Congratulations, you just got yourself a..."
                jump weaponRope
                
            if renpy.random.randint(1,20) = 4:
                "Congratulations, you just got yourself a..."
                jump weaponPotLid
                
            if renpy.random.randint(1,20) = 5:
                "Congratulations, you just got yourself a..."
                jump weaponMegaphone
                
            if renpy.random.randint(1,20) = 6:
                "Congratulations, you just got yourself a..."
                jump weaponSwissKnife
                
            if renpy.random.randint(1,20) = 7:
                "Congratulations, you just got yourself a..."
                jump weaponPoison
                
            if renpy.random.randint(1,20) = 8:
                "Congratulations, you just got yourself a..."
                jump weaponKatana
                
            if renpy.random.randint(1,20) = 9:
                "Congratulations, you just got yourself a..."
                jump weaponStunGun

            if renpy.random.randint(1,20) = 10:
                "Congratulations, you just got yourself a..."
                jump weaponBat

            if renpy.random.randint(1,20) = 11:
                "Congratulations, you just got yourself a..."
                jump weaponNunchaku

            if renpy.random.randint(1,20) = 12:
                "Congratulations, you just got yourself a..."
                jump weaponSickle

            if renpy.random.randint(1,20) = 13:
                "Congratulations, you just got yourself a..."
                jump weaponBow

            if renpy.random.randint(1,20) = 14:
                "Congratulations, you just got yourself a..."
                jump weaponBoomerang

            if renpy.random.randint(1,20) = 15:
                "Congratulations, you just got yourself a..."
                jump weaponFork

            if renpy.random.randint(1,20) = 16:
                "Congratulations, you just got yourself a..."
                jump weaponAxe

            if renpy.random.randint(1,20) = 17:
                "Congratulations, you just got yourself a..."
                jump weaponBox

            if renpy.random.randint(1,20) = 18:
                "Congratulations, you just got yourself a..."
                jump weaponToy

            if renpy.random.randint(1,20) = 19:
                "Congratulations, you just got yourself a..."
                jump weaponBinoculars

            if renpy.random.randint(1,20) = 20:
                "Congratulations, you just got yourself a..."
                jump weaponCrown
        
label weaponPaperFan:
    
    "Paper Fan, (the big artcard type to whack people - Harisen)"
    jump ContinueStory02
    
    
label weaponShotGun:
    
    "Shot gun, (with ammo of 10 shoots)"
    jump ContinueStory02
    
    
label weaponRope:
    
    "Rope with a Ninja hook attached to the end, (Ninja use them in the older days)"
    jump ContinueStory02
    
    
label weaponPotLid:
    
    "Pot Lid (Any pot and pans?)"
    jump ContinueStory02

    
label weaponMegaphone:
    
    "Megaphone, (Hello! Hello! Can you hear me?)"
    jump ContinueStory02

    
label weaponSwissKnife:
    
    "Swiss Knife, (A swiss knife that fit nicely in your pocket.)"
    jump ContinueStory02

    
label weaponPoison:
    
    "Poison in a small bottle, (Very Deadly >w< Be warn.)"
    jump ContinueStory02

label weaponKatana:
    
    "Katana, (With a sharp edge.)"
    jump ContinueStory02

label weaponStunGun:
    
    "Stun Gun, (For the youngs and old.)"
    jump ContinueStory02

label weaponBat:
    
    "Baseball Bat, (BASEBALL ANYONE!?)"
    jump ContinueStory02

label weaponNunchaku:
    
    "Nunchaku, (The thing that Bruce Lee use.)"
    jump ContinueStory02

label weaponSickle:
    
    "Sickle, (A tool that is perfect for keeping your lawn neat.)"
    jump ContinueStory02

label weaponBow:
    
    "Crossbow, (Comes with 10 arrows free of charge.)"
    jump ContinueStory02

label weaponBoomerang:
    
    "Boomerang, (Lets play catch.)"
    jump ContinueStory02

label weaponFork:
    
    "Sliver Fork, (A fine piece of sliverware.)"
    jump ContinueStory02

label weaponAxe:
    
    "Fire Axe, (It will save you in time of crisis.)"
    jump ContinueStory02

label weaponBox:
    
    "Bento Box, (A bento box filled with dilicious food.)"
    jump ContinueStory02

label weaponToy:
    
    "Toy Pistol, (A replica that look as good as the real one.)"
    jump ContinueStory02

label weaponBinoculars:
    
    "Binoculars, (Bird watching is a good hobby.)"
    jump ContinueStory02

label weaponCrown:
    
    "Sliver Crown, (A headgear for the royalty.)"
    jump ContinueStory02
    
label ContinueStory02:
    
    "Now that we are all set, let the game begins~"
i would really apprieciate it if i could get some pointers for this.

kazirahul
Newbie
Posts: 1
Joined: Wed Aug 05, 2009 7:14 am
Contact:

Re: Problem simulating the dice system

#2 Post by kazirahul »

this is good site.

chunderbunny
Regular
Posts: 52
Joined: Sat Feb 09, 2008 1:50 pm
Projects: SSS:Renaissance, Canadense (WIP)
Contact:

Re: Problem simulating the dice system

#3 Post by chunderbunny »

Code: Select all

if renpy.random.randint(1,20) = 1:
You are using an assignment statement here instead of an equivalence statement. Basically you need to change your '=' to '=='.

Code: Select all

if renpy.random.randint(1,20) == 1:
Do this for all you 'if' statements. :)

Edit: Also it occurs to me that you have coded this wrongly anyway. renpy.random.randint will produce a new number every time you call it. This means that it is possible (likely?) that no weapon will be selected.

I recommend changing to something like the following:

Code: Select all

  menu:
        "Choose Weapon":
 
            weapon = renpy.random.randint(1,20)

            if weapon == 1:
                "Congratulations, you just got yourself a..."
                jump weaponPaperfan
               
            elif weapon == 2:
                "Congratulations, you just got yourself a..."
                jump weaponShotGun
               
            elif weapon == 3:
                "Congratulations, you just got yourself a..."
                jump weaponRope
               
            elif weapon == 4:
                "Congratulations, you just got yourself a..."
                jump weaponPotLid

(skip some lines here, you get the idea)

            elif weapon == 19:
                "Congratulations, you just got yourself a..."
                jump weaponBinoculars

            else:
                "Congratulations, you just got yourself a..."
                jump weaponCrown

blueeyes1345
Regular
Posts: 42
Joined: Thu Mar 19, 2009 11:06 am
Projects: Short School Dating Sims Game
Organization: Emyth Zandra
Location: Singapore
Contact:

Re: Problem simulating the dice system

#4 Post by blueeyes1345 »

O.o

ok

thx i will give it a try ^^ thx for the help ^^

Vorsic
Newbie
Posts: 18
Joined: Mon Mar 02, 2009 9:46 am
Contact:

Re: Problem simulating the dice system

#5 Post by Vorsic »

Rather than typing out "Congratulations, you just got yourself a..." several times, why not just put it once before the if statement?

blueeyes1345
Regular
Posts: 42
Joined: Thu Mar 19, 2009 11:06 am
Projects: Short School Dating Sims Game
Organization: Emyth Zandra
Location: Singapore
Contact:

Re: Problem simulating the dice system

#6 Post by blueeyes1345 »

oh yar...

thx for the tips

btw, isit possible to simuate it such that the result that i had obtain before will not appear again?

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem simulating the dice system

#7 Post by KimiYoriBaka »

you can try this:

Code: Select all

$ weapon = 0
while weapon in chosen:
    $ weapon = renpy.random.randint(1,20)
chosen.append(weapon)
then just add
$ chosen = []
into your init block.

blueeyes1345
Regular
Posts: 42
Joined: Thu Mar 19, 2009 11:06 am
Projects: Short School Dating Sims Game
Organization: Emyth Zandra
Location: Singapore
Contact:

Re: Problem simulating the dice system

#8 Post by blueeyes1345 »

hmm... i understand the codes above but it doesn't seems to be the codes i need.

the code you gave me is something tat allow me to store a result i obtain from the dice roll and retrieve it later right?

what i meant is that isit possible to simulate it such that for e.g.
on my 1st roll, i got the result 1

isit possible to simulate it such that on the 2nd roll, the result 1 won't appear again.

Thx for your help all the same ^^ i am sure i can make this code to good use.

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem simulating the dice system

#9 Post by KimiYoriBaka »

That's exactly what that code does. Here's how it works, to make the result not appear again, you need to either keep track of that result, or individually program each case so as not to be able to get that result again (which would be really silly to try). Thus, you make a list to store them in. then when you roll the dice again, you need to make sure result hasn't come up yet, then try again. That's what the while loop is for. It compares the results over and over, untill a new one comes up.

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Problem simulating the dice system

#10 Post by JQuartz »

blueeyes1345 wrote:isit possible to simulate it such that on the 2nd roll, the result 1 won't appear again.
You can use renpy.random.choice and then remove the result from the list like so:

Code: Select all

    
label start:
    $ weapon_list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]

label ContinueStory01:
    menu:
        "Choose Weapon":
            $ weapon=renpy.random.choice(weapon_list)
            $ weapon_list.remove(weapon)
            "Congratulations, you just got yourself a..."
            if weapon == 1:
                jump weaponPaperfan
               
            elif weapon == 2:
                jump weaponShotGun
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]