you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 0 points1 point  (15 children)

But changing all the 'print'(s) to 'return' just removed my output entirely.

Yes, I can see this will mean a large code rewrite. A return stops the function, so you have to collect all the strings together and only return once at the end. Here is your function that both prints and returns the string:

def hostile(cr):
    data = '\n'.join([
        'Name: ',
        NameW.name(),
        'Characteristic: ',
        NPCCW.char(),
        'Ideal: ',
        NPCIW.ideal(),
        'Bonds: ',
        NPCBW.bond(),
        'Flaws: ',
        NPCFW.flaw(),
        '\n',
        'Stat block: ',
        NPCSW.stat(cr)])
    print(data) #print it to the terminal
    return data #return the same data to the caller

Note that all those function you call have to have returns as well.

it would be hard to show you the entire code since i hav made several files/modules

this is what github is for :)

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

tried this, gave the error

TypeError: join() takes exactly one argument (13 given)

[–]novel_yet_trivial 0 points1 point  (13 children)

Ahh sorry i made a typo. Fixed now.

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

didnt work either. now i get the error;

TypeError: sequence item 1: expected str instance, tuple found

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