Page 1 of 1

TypeError: coercing to Unicode

Posted: Thu Feb 14, 2019 10:26 am
by Smaymay
Hi there! I've stumbled upon an error today and after changing up the syntax 100 times to fix it and some research I realised I need help haha. I have this screen with an awful lot of imagebuttons. I'm still using placeholder art atm so I will have to change their positions once I get the finished GUI. To save me a lot of time I thought why not use predefined positions? Here's a snippet of the code:

Code: Select all

    $ bakerypos = Position(xpos=589, ypos=143)
    $ bakerypos2 = Position(xpos=589, ypos=99)

Code: Select all

    imagebutton:
        idle "images/GUI/map/abigale_loc.png"
        if abigale_location == "bakery":
            if bakeryCharAmount == 2:
                pos ("bakerypos")
            else:
                pos ("bakerypos2")
But it gives me the folliwing error at pos ("bakerypos")

Code: Select all

TypeError: coercing to Unicode: need string or buffer, int found
I guess it's a syntax error? (My achilles' heel haha) The positions are numbers and not strings so if I understand correctly it can't convert a string to an int. But I don't know how I should write this down instead. Any thoughts? :)

Re: TypeError: coercing to Unicode

Posted: Thu Feb 14, 2019 10:54 am
by Queex
I think you need to remove the quotes round the variable names:

pos(bakerypos)

When you put it in quotes, it's treated as a string, not a reference to the variable you've defined.