The Artima Developer Community
Sponsored Link

Python Buzz Forum
shallow copies in python

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Terra Caines

Posts: 65
Nickname: terraff
Registered: Feb, 2008

Terra's blog on creating a 3d tactics game in python
shallow copies in python Posted: Jan 4, 2009 6:41 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Terra Caines.
Original Post: shallow copies in python
Feed Title: Terra's blog
Feed URL: http://terracaines.blogspot.com/feeds/posts/default?alt=rss
Feed Description: I am developing a open source 3d tactical game in python. This is showing the steps.
Latest Python Buzz Posts
Latest Python Buzz Posts by Terra Caines
Latest Posts From Terra's blog

Advertisement
I had a fairly interesting bug today.

When going to cast a second spell the grid targeting was hitting every previous unit and position.

I tracked it down to the fact that I made a copy of the executing object.

Now I made a copy to it so that it wouldn't interfere with the objects on the unit. So why did that cause more problems?

Because in my code for the object I would say add 3 units to a list. Because its a shallow copy it would also add it to the previous object. And you cant use deep copyies as that would duplicate the units.

However when I went to clear the list to reset it I just created a new one like self.list = []

So what it did was clear the copied variable and not the original. Thus making the copy actually made things worse as it made the copy interfere in only some ways. So I just removed the copy method and things started working again.

This is an interesting bug because I could have clearly spent less time on it and still fixed it by clearing the list. But I spent the extra time to actually remove the copy method because I knew that would cause me trouble in the future if I didn't

It should be noted though that the actions must be updated to deal with repeated use for example on my move object. This is however much more simple and better than trying to debug the copying stuff. Either could be done, but the latter is like doing security in php

Read: shallow copies in python

Topic: Updates to voices Previous Topic   Next Topic Topic: Adding sound

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use