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
The interpreter is reading that as a variable, however it needs to be a string.
makeOrb("orb0",3,2,2)
(Nov-16-2018, 10:45 PM)stullis Wrote: [ -> ]The interpreter is reading that as a variable, however it needs to be a string. makeOrb("orb0",3,2,2)
I tried that but got this erre:
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?
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)