Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nicholas Anstis
2,095 PointsShop System
So I made a shop system that allows you to buy item from gold. Once you buy the item in the shop the item you bought in the shop gets re located to a list named curweap
I also made a function that says if the current weapon is = Great Sword (name of the item) the attack should be X. But for some reason it doesn't work the item gets added properly but after that the damager counter doesn't take place.
My code : https://w.trhou.se/7w6f3s5aqf
The code that says if the item is X damage = Y is on line
Hope any of you can tell me what i'm doing wrong :} Ps (I know i've been asking a lot of question about the game i'm trying to create on the forum for the past few day but, hmm the forum is meant to be used :P)
3 Answers
Steven Parker
243,228 PointsI'm feeling a bit like your personal mentor. But I like your enthusiasm.
I didn't see any code that might perform the "if the item is X damage = Y" function you were describing. The damage appears to be applied on line 144 and reported on line 145:
enemy.health -= PAttack
print("You dool {} damage!".format(PAttack))
By the way, what is "dool"? I hope you're not Iranian!
Also, on line 139, you have: "if PAttack == PlayerIG.base_attack / 2:" — This can NEVER be true when base_attack is an odd number. You probably want: "if PAttack <= PlayerIG.base_attack / 2:". There's a similar issue on line 151.
Nicholas Anstis
2,095 PointsAlso "PAttack = random.randint(math.floor(PlayerIG.base_attack / 2), PlayerIG.base_attack)" Should be right since I added an if that looks for the item in the player's inventory for an item. So if it finds it it'd set the attack_damage to the given value ? Line 24 (PAttack is assigned to random.randint(math.floor(PlayerIG.base_attack / 2), PlayerIG.base_attack)
Are you sure that this is the problem?
Steven Parker
243,228 PointsIt's not related to the damage issue. But when base_attack is an odd number, dividing it by 2 will produce a non-integer. That's why math.floor was needed for randint. So since PAttack is always an int, it can never be equal to PlayerIG.base_attack / 2 when PlayerIG.base_attack is odd. But if you use <= instead of ==, it will still be true for the lowest possible value of PAttack.
Nicholas Anstis
2,095 PointsI can't get it to work D: could you please send the code that needs to be change? :}
Nicholas Anstis
2,095 PointsNicholas Anstis
2,095 PointsThe Code that says "if the item is X damage = Y" is on line 24 on the @property (attack(self))
(I'm not iranian it's just that english is not my native language so i don't know what the past of deal is :P XD)
But still thanks again :} Ill try to fix it with what you've given me
Steven Parker
243,228 PointsSteven Parker
243,228 PointsI overlooked that "@property" decorator. But I'm not sure you're using it correctly — wouldn't it need a setter method?
And I think the word you want is "dealt".
Nicholas Anstis
2,095 PointsNicholas Anstis
2,095 PointsCould you give me an example please ? It would be much appriciated :}
Steven Parker
243,228 PointsSteven Parker
243,228 PointsI'm going to refer you to the Python Docs for this one. But as I understand it, this kind of property management only works on classes that derive from object anyway.
My recommendation is to just have an ordinary method that you call to change the weapon. So inside Player, you might have something like this:
And then in the store, instead of "
PlayerIG.curweap = option" you would have: "PlayerIG.setweap(option)"But I still think you should pick store items by number instead of name.
Nicholas Anstis
2,095 PointsNicholas Anstis
2,095 Points:D:D:DOE;MEIFNUENeki fne fwof ...... I appriciate your help A LOT but it looks like i'm really dumb .-. I'm sorry but I can't get it right :()
My new code : https://w.trhou.se/nwk4yxjmhq
Steven Parker
243,228 PointsSteven Parker
243,228 PointsYou forgot the 2nd part of my suggestion. Remember I said:
And then in the store, instead of "PlayerIG.curweap = option" you would have: "PlayerIG.setweap(option)"You still need to change that on line 231.
Nicholas Anstis
2,095 PointsNicholas Anstis
2,095 PointsOh Dang you really are Good! It worked thanks a lot it means a lot :] Having such a great community is awesome :D
Thanks you Steven and I 100% i will have more questions in the future :}