d2jsp
d2jsp Forums > Programmer's Haven > Little Python Help
Add Reply New Topic New Poll
RocketRaccoon
#1 Oct 25 2012 06:30pm
Group: Member
Posts: 18,963
Joined: Nov 13 2008
Gold: 1,392.14
can some1 tell me how this function works? Not sure what to give it as an input (like I kno its a list but not sure how that list is formatted)

Quote
def putBlock(block):

    if (type(block)!=list):
          print ("Error: Not a list")
          return
    else:
          print ("List Detected")
   
   
    label=block[0]
    p=[]
    for coord in block[1:]:
          p.append(coord)

    color=fetchColor(label)

    turtle.begin_fill()
    turtle.fillcolor(color)
    turtle.penup()
   
    k=p[0]
   
   
   
    turtle.setpos(k[0],k[1])
    turtle.pendown()
    for i in range(0,len(p)):
          k=p[i]
         
          if (type(k)!=tuple):
              print ("Error: Not a Tuple")
              return
          else:
              print ("Tuple Detected") 
             
          turtle.setpos(k[0],k[1])
    k=p[0]         
    turtle.setpos(k[0],k[1])       
   
   
    turtle.end_fill()
    turtle.penup()

    return
carteblanche
#2 Oct 25 2012 07:24pm
Group: Member
Posts: 32,618
Joined: Jul 23 2006
Gold: 1,130.00
Looks like a list of coordinates for turtle graphics.
rockonkenshin
#3 Oct 25 2012 07:59pm
Group: Member
Posts: 11,636
Joined: Feb 2 2004
Gold: 434.84
Quote (carteblanche @ Oct 25 2012 08:24pm)
Looks like a list of coordinates for turtle graphics.


This, but without the calling method or some other code it's hard to tell.
RocketRaccoon
#4 Oct 25 2012 09:32pm
Group: Member
Posts: 18,963
Joined: Nov 13 2008
Gold: 1,392.14
Quote (carteblanche @ Oct 25 2012 07:24pm)
Looks like a list of coordinates for turtle graphics.


Quote (rockonkenshin @ Oct 25 2012 07:59pm)
This, but without the calling method or some other code it's hard to tell.


there is more code to that (like 12 or so different functions that call upon each other), I didn't wanna post it all because I wanna kinda half figure it out on my own, if I can understand this function to get it running on one instance I can solve the whole problem, but if you guys wanna see the rest of it for better understanding, lmk.
irimi
#5 Oct 25 2012 09:35pm
Group: Member
Posts: 3,634
Joined: Sep 15 2011
Gold: 1,771.00
the input it seems to expect is that the first element of the list is a list of properties, while the remainder of the list is just a bunch of coordinates
RocketRaccoon
#6 Oct 25 2012 11:08pm
Group: Member
Posts: 18,963
Joined: Nov 13 2008
Gold: 1,392.14
thank you guys I figured it out :D it was so hard and then so simple -.-
rockonkenshin
#7 Oct 26 2012 06:50am
Group: Member
Posts: 11,636
Joined: Feb 2 2004
Gold: 434.84
Quote (Shamx @ Oct 26 2012 12:08am)
thank you guys I figured it out :D  it was so hard and then so simple -.-


Welcome to programming ;)

Quote (irimi @ Oct 25 2012 10:35pm)
the input it seems to expect is that the first element of the list is a list of properties, while the remainder of the list is just a bunch of coordinates


I noticed that after I posted. Seems like really bad design and the list should probably be broken out into a better data structure.
RocketRaccoon
#8 Oct 26 2012 08:59am
Group: Member
Posts: 18,963
Joined: Nov 13 2008
Gold: 1,392.14
Quote (rockonkenshin @ Oct 26 2012 06:50am)
Welcome to programming ;)



I noticed that after I posted. Seems like really bad design and the list should probably be broken out into a better data structure.


Ya once I figured out how the list was supposed to look like, formatting the data in the text file to make the functions work wasn't too hard.
Go Back To Programmer's Haven Topic List
Add Reply New Topic New Poll