#๐Ÿ”’ Random Choice Issues

28 messages ยท Page 1 of 1 (latest)

opaque hornetBOT
#

@pure fiber

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Please react with โœ… to upload your file(s) to our paste bin, which is more accessible for some users.

pure fiber
#

`while dungeon:
draw()
print('You Encountered A',enemy,'In The Dungeon!\nDefeat It For Blood')
draw2()
clear()
draw()
print(enemy,'HP:',str(hp),'/',str(hpmax))
print(name,'HP:',str(HP),'/',str(HPMAX),'\n')
print('1. ATTACK')
if POT > 0:
print('2. USE POTION (25HP)')
print('3. RETURN TO TAVERN')
draw2()

    choice = input('>>> ')
    clear()
    if choice == '1':
        hp -= ATK
        print(name,'Dealt',str(ATK),'Damage To The',enemy,)
        if hp > 0:
            HP -= ATK
            print(enemy,'Dealt',str(atk),'Damage To',name,)
    elif choice == '2':
        if POT > 0:
            POT -= 1
            heal(25)
            HP -= atk
            print(enemy,'Dealt',str(atk),'Damage To',name,)
            draw()
            print(enemy,'HP:',str(hp),'/',str(hpmax))
            input('>>> ')
        else:
            print('0 Potions Remaining')
        input('>>> ')
                
    elif choice == '3':
        save()
        clear()
        dungeon = False
        play = True

    if HP <= 0:
        print(name,'has been defeated...')
        draw2()
        dungeon = False
        play = True
    elif hp <= 0:
        BLD += bld
        print(name,'Has Defeated',enemy)
        print('You Have Accquired',bld,'Litres Of Blood')
        dungeon = False
        play = True`
ripe kernel
#

Ok, there's some code ... did you have a question?

#

pro tip: I cannot run that code because many things (like draw) are undefined
also pro tip: I probably can't answer your question, whatever it is, unless I can run the code and see what you're seeing

errant reef
#

@pure fiber ^^

opaque hornetBOT
cyan widget
#

@pure fiber If I might posit a guess, are you wondering why the same enemy is picked over and over while the game is running?

pure fiber
#

yes

#

and also when a start a new battle its at 0hp

cyan widget
#

This line

enemy = random.choice(e_list)
``` makes a random choice. One time.

This later block you use:
```py
if choice == '1':
    clear()
    enemy
    dungeon = True
    play = False

enemy returns the value of the randomly-chosen enemy. But it does not re-run the random choice.
You need to call random.choice(e_list) again and assign that again if you want something new.

cyan widget
#

!e

import random

stuff = [1, 2, 3, 4, 5, 56, 7, 7, 686, 8, 68, 6]
selection = random.choice(stuff)
print(selection) # prints a value selected
print(selection) # will print the same value
print(selection) # and again

See, the value of selection is not connected to the random.choice method in any way. The selected value has been selected, and that's it: it is simply an integer that doesn't change:

opaque hornetBOT
cyan widget
#

!e To select it again, we must... select it again ๐Ÿ™‚

import random

stuff = [1, 2, 3, 4, 5, 56, 7, 7, 686, 8, 68, 6]
selection = random.choice(stuff)
print(selection)
selection = random.choice(stuff)
print(selection)
selection = random.choice(stuff)
print(selection)
#

(sometimes it might select a thing again, but the point stands)

opaque hornetBOT
cyan widget
#

The fix may be as simple as moving this block:

enemy = random.choice(e_list)
hp = e_stats[enemy]['H']
hpmax = hp
atk = e_stats[enemy]['A']
bld = e_stats[enemy]['B']

while run:
``` into the `while` loop below:
```py
while run:
    enemy = random.choice(e_list)
    hp = e_stats[enemy]['H']
    hpmax = hp
    atk = e_stats[enemy]['A']
    bld = e_stats[enemy]['B']
pure fiber
#

oh ok

#

ill try it

cyan widget
#

Move it around as you see fit; but whenever you want to select a new enemy, you have to go through all the motions of selecting a new enemy. ๐Ÿ™‚

pure fiber
#

ah its fixed

#

thx so much

#

!close

opaque hornetBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.