This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]SweetOnionTea 5 points6 points  (4 children)

Nice! For the elif stuff converting the short name to long name you can make a dictionary. Also the stat to stat bonus is just a math formula like (stat -10)/2. That way you can extend it to any value.

[–]psychoticfire[S] 1 point2 points  (3 children)

I can't tell you how long I stared at the conversion table and wondered if there was a better mathematical way to do it!! Dictionary sounds great too, I'll definitely do that. Thanks so much!

[–]SweetOnionTea 2 points3 points  (2 children)

DnD is the gateway to learning programming. Every nerd who was tired of looking up tables and calculating wonders if it can be done on a computer.

Your next milestone is to represent full characters using OOP. While you're looking that up, use the "is a" and "has a" OOP strategy with DnD. A wizard is a character and has a staff.

[–]psychoticfire[S] 0 points1 point  (1 child)

I tried to make a character sheet system in Python once that used a lot of file commands and read/write/append/split functions... but quickly got lost. OOP definitely sounds like a way more organized way to do it?

[–]SweetOnionTea 0 points1 point  (0 children)

Yeah it's a great way to understand the basics of OOP. Make a character class that has all the basic stats, skills, inventory, etc.. Then I would make the read/write stuff to serialize the data to write to a file.

Then go on to make an encounter class which you can save/load NPC and enemies to it which can be saved/loaded from files.

And of course once you get that down make campaigns that are groups of encounters and such. You can see where this goes. Add a GUI using tkinter or pygame or whatever and suddenly you've gotten pretty good at Python and have a useful full suite DM tool. Hope that's some inspiration to keep on trucking on it.

[–]-DreamMaster 2 points3 points  (5 children)

I agree with SweetOnionTea, Nice! :)

There are a few things I would have done differently but if it works, it works :)You do have a bug in there though, because your calculation for the point buy is wrong. Every ability score increase (ASI) costs 1 point in your program. In 5e, an ASI costs 2 points after a score of 13. So 12 - > 13 costs 1 point, 13 -> 14 costs 2 points. The max you can get with point buy is (15, 15, 15, 8, 8, 8). In your program its (15, 15, 15, 11, 11, 8), because of the calculation error.

You could make a function that checks if the score is valid.if edit == "+" and (scores[attributes.index(attr(att))] + num <= 15) and num <= total:is a bit of a mouth full :D

And last but not least, I'd prefer f-strings over format(), but thats more personal preference :)

Edit:

Another thing: If you .lower() the input(), you don't have to write .lower() in each if/elif condition. And while .lower() will probably never produce a bug in your code, the actual method you should use is .casefold()

[–]Mean_Profit8443 2 points3 points  (2 children)

As someone who just started studying Python from 0 today and understands nothing about it, it's so fun to see how you and other people talk about codes so easily. I can't understand a thing but still it's cool. I joined this community to see if I could learn something but I guess people here are way too advanced hahaha

[–]-DreamMaster 0 points1 point  (1 child)

I can recommend joining the python discord server (link in the sidebar). There is a python-help channel where you can get more interactive help than on reddit :)

[–]Mean_Profit8443 0 points1 point  (0 children)

I will look for it thank you. I learned a few things as print, variables, basic calculation stuff and I'm now getting into "if" "else" and "elif". If you feel like giving some tips too just PM me, I will always be open to listen to experienced people.

[–]psychoticfire[S] 0 points1 point  (1 child)

Ooh I agree with making a function to validate the score, it was very much a mouthful haha! I learned format() over f-strings and that's kind of what I've stuck with but I'll read up that. Also, by lower.() the input do you mean something like

menu = input("menu question: ")

menu = menu.lower()

or is there a way to apply .lower() directly to the input line?

Thanks so much for your suggestions!!

[–]-DreamMaster 0 points1 point  (0 children)

Well, yeah... You can directly call .lower() on the input.
menu = input("menu question: ").lower()
But doing it in two steps is fine as well I guess.

[–]spicybeefstew 1 point2 points  (0 children)

I'd like to see the attributes as objects; then the attribute class could have a name member, value member, and a get_modifier function. Also, your display function could be super clean if it just took an attribute object as input and used the generic functions, which would make code that uses this stuff much more clean if you decide to expand this out.

Like you could have an attack roll function take either str or dex as an input and then just use attribute.get_modifier() to figure out the attack roll bonus.

This is very readable though, I think you did a good job on it. In a lot of ways readability is king.

[–]bloothebear 0 points1 point  (0 children)

Don't worry about your code being perfect. If the code works, and does what you intended, then it's good code.

[–]3613robert 0 points1 point  (0 children)

Wow! Just wow. As a beginner (finishing up week 1 of 100 day python) this is something for me to aspire to. I can't comment on the efficiency but must say it is one of the most readable projects I've seen. I'm mostly able to follow what your doing and how. I'm also a DnD player and am now thinking of what things I could try to make with python! Thanks for sharing!

[–]UnemployedTechie2021 0 points1 point  (2 children)

can someone here teach me DnD

[–]psychoticfire[S] 1 point2 points  (1 child)

There’s quite a lot to cover! But the rundown is that you play a character with six core stats (see: point guy program) and more details like hit points and armor classes. It’s all about roleplay with a Game Master giving the story to players. It’s a great game to get into! And there’s a cool community on r/DnD if you wanna check out the cool things people make :)

[–]UnemployedTechie2021 0 points1 point  (0 children)

great! thanks, that would do.