Thread: Help plz

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    5
    Rep Power
    0

    Exclamation Help plz


    I have a Danish script, and im pretty new and this should be a "RPG" game. i just need a script thats repeat this:

    Code:
    damage1 = random.randint(3, 26)
    damage2 = random.randint(1, 24)
    damage3 = random.randint(2, 23)
    damage4 = random.randint(2, 19)
    this is the whole script:

    Code:
    # -*- coding: cp1252 -*-
    
    #Dette er en BETA version
    #Og det er et tekst og tur baseret "RPG"
    
    
    
    
    
    
    import time
    import random
    
    life1 = 500 
    life2 = 500
    life3 = 500
    life4 = 500
    
    damage1 = random.randint(3, 26)
    damage2 = random.randint(1, 24)
    damage3 = random.randint(2, 23)
    damage4 = random.randint(2, 19)
    
    Player1 = random.randint(1, 4)
    Player2 = random.randint(1, 4)
    
    print "Mulige figurer:"
    print "1: Samus"
    print "2: Mario"
    print "3: Mewtwo"
    print "4: Kirby"
    print ""
    time.sleep(2)
    
    print "Finder spiller 1's figur..."
    time.sleep(2)
    if Player1 == 1:
        print "Spiller 1 blev Samus."
    elif Player1 == 2:
        print "Spiller 1 blev Mario."
    elif Player1 == 3:
        print "Spiller 1 blev Mewtwo."
    elif Player1 == 4:
        print "Spiller 1 blev Kirby."
    else:
        print "Spiller 1 blev desværre ikke nogen... SÅ KAN DU LÆRE DET!!!"
    print ""
    time.sleep(1)
    print "Finder spiller 2's figur..."
    time.sleep(2)
    if Player2 == 1:
        print "Spiller 2 blev Samus."
    elif Player2 == 2:
        print "Spiller 2 blev Mario."
    elif Player2 == 3:
        print "Spiller 2 blev Mewtwo."
    elif Player2 == 4:
        print "Spiller 2 blev Kirby."
    else:
        print "Spiller 2 blev desværre ikke nogen... SÅ KAN DU LÆRE DET!!!"
    time.sleep(1)
    print ""
    print "Vent mens figurene gør klar til kamp."
    time.sleep(2)
    print ""
    print ""
    print "Sådan gør du.: "
    print "Skriv: Attack, attack eller ATTACK for at angribe."
    
    raw_input ("Spiller 1: ")
    Im using:
    Win XP
    python 2,4
    please help me.

    i know many of u in there knows it
    Last edited by jomik1993; May 4th, 2005 at 02:14 PM. Reason: informations
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    what do you mean by repeat?

    are you wanting it to repeatily keep adding a randome integer to a verible? possible lists are what your looking for?

    Code:
    #!/usr/bin/env python
    import random
    
    blah = []
    for i in range(1, 10):
        blah.append(random.randint(3, 26))
    
    for c in blah:
       print c
    that would put 10 random numbers into the list blah and then print them out one at a time.

    However i do not know if this is what your looking for you must be more specific.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You could also do this using a list comprehension or generator expression, which would be more Pythonic IMO.

    Code:
    >>> randomNumbers = [random.randint(1, 26) for r in range(4)]
    >>> randomNumbers
    [14, 22, 8, 10]
    >>> 
    >>> randomNumbers = [random.randint(*r) for r in ((3, 26), (1, 24), (2, 23), (2, 19))]
    >>> randomNumbers
    [12, 17, 15, 6]
    >>>
    The second example actually clones the piece of code you posted however if you don't need to vary the range of numbers you can simply use the first which is much more readable.

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    5
    Rep Power
    0
    i mean, it must generate numbers forever, (just generate every time i need it) but one of my friends maked it. He used the 1D20 system like KotOR2 (Knights of the Old Republic 2) and that worked...

    now i just need a loop...
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You need to use a while True loop, this simply lets you do something forever .
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    5
    Rep Power
    0
    whats the code to a while true loop?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    the while loop loops for ever because it is always True
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Here an example should you need it. It's pretty straight forward .

    Code:
    >>> while True:
    ...     print 'again and'
    ... 
    again and
    again and
    again and
    again and
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo