#๐ Random Choice Issues
28 messages ยท Page 1 of 1 (latest)
@pure fiber
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.
`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`
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
@pure fiber ^^
Please react with โ
to upload your file(s) to our paste bin, which is more accessible for some users.
@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?
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.
And for that you'd need a way to exclude it from the original list.
Perhaps randomly shuffle the list and .pop() an enemy from it, instead?
!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:
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 56
002 | 56
003 | 56
!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)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 7
002 | 5
003 | 56
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']
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. ๐
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.