Python Forum
Can i make this work in any way?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can i make this work in any way?
#1
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
Reply
#2
The interpreter is reading that as a variable, however it needs to be a string.

makeOrb("orb0",3,2,2)
Reply
#3
(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?
Reply
#4
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)
Reply
#5
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hi need help to make this code work correctly atulkul1985 5 699 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 626 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,257 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Make my py script work only on 1 compter tomtom 14 3,735 Feb-20-2022, 06:19 PM
Last Post: DPaul
  Cannot make 'pandas' module to work... ellie145 2 4,136 Jan-05-2021, 09:38 PM
Last Post: ellie145
  Is there anyway to make this work? dre 3 2,108 Nov-26-2020, 12:40 PM
Last Post: jefsummers
  Cannot Make the python Code work ErnestTBass 4 2,608 Apr-23-2020, 02:42 PM
Last Post: snippsat
  if, or, in, else in 1 line - how to make it work? zarize 2 1,813 Sep-10-2019, 04:51 PM
Last Post: zarize
  To make an algorithm work faster pianistseb 3 2,755 Apr-01-2019, 08:42 AM
Last Post: Gribouillis
  Rewrite a function to make it work with 'bottle-pymysql' nikos 1 1,934 Feb-26-2019, 02:59 PM
Last Post: nikos

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020