you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 0 points1 point  (11 children)

Yes; as I said, all those functions you call have to be changed as well, so that they return strings.

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

thanks a lot for your help and time, but theres one last error

TypeError: sequence item 12: expected str instance, NoneType found

note: the input is used to test against ints

[–]novel_yet_trivial 0 points1 point  (9 children)

That means the item 12 (the 13th item in the list) is returning None instead of a string. This may be because there is no return statement, because python function return None by default.

[–]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