Can i make this work in any way? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Can i make this work in any way? (/thread-14155.html) |
Can i make this work in any way? - Stefanovietch - Nov-16-2018 import turtle as tl orbs = [] #Screen home = tl.Screen() home.bgcolor("black") home.title("Home Screen") #Orbs def makeOrb(name,life,x,y): global orbs name = tl.Turtle orbs.append([name, life]) name.penup() name.color("green") name.shape("circle") name.write(life,align="center") name.setposition(x, y) makeOrb(orb0,3,2,2)I would like to be able to just type makeOrb and have one appear where i want to. Otherwise i will just have to write out everything for every orb I forgot to add the error: orb0 is not defined RE: Can i make this work in any way? - stullis - Nov-16-2018 The interpreter is reading that as a variable, however it needs to be a string. makeOrb("orb0",3,2,2) RE: Can i make this work in any way? - Stefanovietch - Nov-17-2018 (Nov-16-2018, 10:45 PM)stullis Wrote: The interpreter is reading that as a variable, however it needs to be a string.I tried that but got this erre:makeOrb("orb0",3,2,2) TypeError: 'str' object is not callable the turtle name can't be an string and the input has to be one. which other variable will work? RE: Can i make this work in any way? - stullis - Nov-17-2018 Ah! Sorry, I didn't look carefully enough. Your function takes name as an argument and isn't actually using it. Instead, you're resetting immediately to tl.Turtle. Also, that line needs to be name = tl.Turtle() Try this instead: import turtle as tl orbs = [] #Screen home = tl.Screen() home.bgcolor("black") home.title("Home Screen") #Orbs def makeOrb(life,x,y): global orbs name = tl.Turtle() name.penup() name.color("green") name.shape("circle") name.write(life,align="center") name.setposition(x, y) orbs.append([name, life]) makeOrb(3,2,2) RE: Can i make this work in any way? - Stefanovietch - Nov-17-2018 (Nov-17-2018, 12:04 PM)stullis Wrote: Ah! Sorry, I didn't look carefully enough. Your function takes name as an argument and isn't actually using it. Instead, you're resetting immediately to tl.Turtle. Also, that line needs to be name = tl.Turtle() Try this instead:Thx, it worked |