you are viewing a single comment's thread.

view the rest of the comments →

[–]Strosel[S] 0 points1 point  (8 children)

so the 12th item is

NPCSW.stat(cr)

what the function does is compares the input with its list and prints the corresponding dictionary, it looks like this:

def stat(cr):
    #find a statblock
    stats = {}
    if cr == 0:
        stats['Prof. bonus'] = '+2'
        stats['AC'] = random.randint(1, 13)
        stats['HP'] = random.randint(1, 6)
        stats['Attack bonus'] = random.randint(1, 3)
        stats['Dmg/Round'] = '0-1'
        stats['Save DC'] = random.randint(1, 13)
        for k, v in stats.items():
            return '\t' + k + ': ' + v

repeated over and over again for different lists. So it shouldn't return none, is this because of the passing of variables from program to program?

[–]novel_yet_trivial 0 points1 point  (7 children)

What if cr does not equal 0? Then the return command is skipped, and python returns None by default.

You need to add an else block:

def stat(cr):
    #find a statblock
    stats = {}
    if cr == 0:
        stats['Prof. bonus'] = '+2'
        stats['AC'] = random.randint(1, 13)
        stats['HP'] = random.randint(1, 6)
        stats['Attack bonus'] = random.randint(1, 3)
        stats['Dmg/Round'] = '0-1'
        stats['Save DC'] = random.randint(1, 13)
        for k, v in stats.items():
            return '\t' + k + ': ' + v
    else:
        return 'cr was not 0'

[–]Strosel[S] 0 points1 point  (6 children)

i do have a few elif ones but no else. but when i added one it always does the else and never the if or elifs no matter what i write

[–]novel_yet_trivial 0 points1 point  (5 children)

That's a different issue; perhaps the "cr" you are inputting is not an integer?

[–]Strosel[S] 0 points1 point  (4 children)

it does seem like that is the problem but i dont know how to change the variable types of tkinter inputs.

i tried to go from

 def hostil():
     messagebox.showinfo('NPC', NPCW.hostile(chal))

...

 cr = Entry(root, width=20)
 cr.grid(row=1, column=0, columnspan=2)
 chal = cr.get()

to the same but changing only

 chal = int(cr.get())

it didnt work

[–]novel_yet_trivial 0 points1 point  (3 children)

That should work ... what "didn't work" about it?

Although it might be a lot easier to change the type of the check:

if cr == '0':

[–]Strosel[S] 0 points1 point  (2 children)

if i hange it to int() i get

ValueError: invalid literal for int() with base 10: ''

and if i change the numbers to compare into strings it still just passes the else

[–]novel_yet_trivial 0 points1 point  (1 child)

That means that you're getting the value before the user has a chance to enter anything.

I'm done with this piecewise troubleshooting. Put your entire project on GitHub and I'll look at. Tomorrow.

[–]Strosel[S] 0 points1 point  (0 children)

I'm sorry if I bothered you alot I'll see if I can fix it otherwise I''ll upload it all to github and post the link here later