#๐ Homework Help #2 - Noob coder tries to code and fucking dies part 2
68 messages ยท Page 1 of 1 (latest)
@polar bobcat
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.
๐ชฆ
Background information:
The battle system is already coded and is a pretty simple "just do this/that according to the instructions, don't touch anything else"
So right now I'm coding this archmage character which is directly based off the mage
so the class of Archmage [ignore spelling] is based off mage
What I need it to do is that if everyone on the team is dead except it, then it will deal 2 x [self.intelligence] damage to every character on the enemy team
I presume what is wrong here is this code, but I cannot understand for the love of my life why.
For one, I don't know how to target all enemies in this, whether it's using an for i in x loop or something. [rn it's set to target a random enemy, but it's there to ensure the code even runs in the first place]
If you need me to send the other files, by all means ask me, since this is the most complex assignment thus far
I just wanna do the hard one first so I can learn, cuz the easier one is just a simpler "sorting" one
Oh
!paste
So that everyone can easily read your code, you can paste it in this website:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
Fuck my life
I forgot
`class ArchMage(Mage):
def init(self):
super().init()
self.name = 'ArchMage'
self.cost = 600
def cast_special(self, my_team, enemy):
if all_dead(my_team) == True:
self.mana -= mana_cost
target = rand_alive(enemy)
dprint(f'Cast KABOOOOOOM! (Damage {self.int*2}) to every enemy!')
enemy[target].got_hurt(self.int*2)`
i'm ACTUALLY a chud larper [ignore me saying actual brainrot, i apologise, this is just how i am at times, i do not mean this]
also, it's not clear what the functions and arguments you're using actually are just from that block
does that i mean i have to send like the whole thing
look at the embeded example, it's 3 backticks followed by py
at the very least you should provide an attempt and the resulting error
class ArchMage(Mage):
def __init__(self):
super().__init__()
self.name = 'ArchMage'
self.cost = 600
def cast_special(self, my_team, enemy):
if all_dead(my_team) == True:
self.mana -= mana_cost
target = rand_alive(enemy)
dprint(f'Cast KABOOOOOOM! (Damage {self.int*2}) to every enemy!')
enemy[target].got_hurt(self.int*2)
you can actually just copy the embedded example and replace the hello world line until you get the hang of it
right
anywho, are you getting an error?
Team A:
Members: | ArchMage
Hitpoints: | 800
Strength: |
Max. Mana: | 50
Current M: | 50
Team B:
Members: | Fighter| Fighter| Mage| Fighter| Fighter
Hitpoints: | 1200| 1200| 800| 1200| 1200
Strength: | 100| 100| | 100| 100
Max. Mana: | | | 50| |
Current M: | | | 50| |
Team A member 0 ArchMage acts
Strike enemy 4 with spell
Fighter hurt with remaining hp 800.
Team A:
Members: | ArchMage
Hitpoints: | 800
Strength: |
Max. Mana: | 50
Current M: | 30
Team B:
Members: | Fighter| Fighter| Mage| Fighter| Fighter
Hitpoints: | 1200| 1200| 800| 1200| 800
Strength: | 100| 100| | 100| 100
Max. Mana: | | | 50| |
Current M: | | | 50| |
Team B member 3 Fighter acts
Hurt enemy 0 by damage 100.
ArchMage hurt with remaining hp 700.```
example output. usually at this point the archmage will start using its cast_special, but it isn't
The thing is that I consider two kinds of errors:
One is an actual error where the whole thing just doesn't run. Here it's running, it's just that it's not doing what I want exactly
The cast_special() is supposed to be designed so that when there is only one person left on the team [that being the archmage themselves] they will cast their special attack
The only thing I am really supposed to edit heavily is the second file, which is characters.py
so your hero is inhereting cast from the base mage class right?
pretty much
they will have the default action cast, and then a special cast for when there is one more
I kind of realise it now
I think I didn't put a condition for that cast, so the code firsthand reads it and assumes to just keep casting normally
And it ignores the special cast function i wrote
yep, the cast that it's inheriting doesn't evaluate any criteria
right, do i need to redefine cast then?
Do all subclasses of mage have special casts?
Yes
Normal mage is just that
Archmage is mage + special kaboom cast only activates if all but them are dead
Necromancer is mage + revive if a member is dead [i'll deal with this later]
I imagine what I need to do is redefine cast so that it's conditional
you can do it on in the parent or the child (forgive my vocab, I write very little OOP)
but yes, that was the direction I was going in
I'm gonna rewrite the child, would I just literally redefine the entire cast function, aka copypaste it and then add the condition, as such
if all_dead(my_team) == False:
self.mana -= mana_cost
target = rand_alive(enemy)
dprint(f'Strike enemy {target} with spell')
enemy[target].got_hurt(self.int)
else:
self.mana -= mana_cost
target = rand_alive(enemy)
dprint(f'Cast KABOOOOOOM! (Damage {self.int*2}) to every enemy!')
enemy[target].got_hurt(self.int*2)```
After this, I would need to figure out how I have it deal damage to every enemy
iterating is the simplest, nothing else comes to mind for walking through a list
right...
so just a for i in enemy_team whatever kinda shit
yep
Ugh
This is due in 24 hours and I'm gonna grind to get this shit done
I am so bad at coding it hurts I'm sorry
seems fine to me
AttributeError: type object 'super' has no attribute 'act'
fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuucckkk
class ArchMage(Mage):
def __init__(self):
super().__init__()
self.name = 'ArchMage'
self.cost = 600
def cast(self, my_team, enemy):
if all_dead(my_team) == True:
self.mana -= mana_cost
for i in enemy:
target = enemy[i]
enemy[target].got_hurt(self.int*2)
dprint(f'Cast KABOOOOOOM! (Damage {self.int*2}) to every enemy!')
super.act(self, my_team, enemy)```
oh im dumb that's what the py does
so it's telling you that mage.act() isn't defined
hmm or maybe not?
I'm seeing that it is, as I said my OOP is weak
perhaps, self.act?
or just act()
act is not defined
hmmm
you may be right about the self
Sensational fucking coder
I'm working on a project and don't want to derail you by giving bad advice where I'm not 100% myself. I'll keep an eye on the thread and help where I can though.
ok thanks, no worries
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.