O and a little tip i suppose (im no python guru by far), taken from the last line of >>> import this
Namespaces are one honking great idea -- let's do more of those! doing something like import bullet vs from bullet import * is making use of the bullet namespace and assuring that stuff you access under that namespace is and stays there. On Jun 8, 10:45 pm, dasacc22 <[email protected]> wrote: > Im not sure what possessed me to fix this but here you go, > > http://www.dasa.cc/shipshowdownfix.tar > > Basically you were mismanaging the global bullets list. So when you > thought you were clearing your bullet list you were actually setting > everything in the list to None and clearing a copy of it. So then the > game kicks in and finds a bunch of stuff in your bullet list but cant > seem to set the x attribute for a None object. > > To fix, i basically removed all the global bullets from the code, then > i changed your > from bullet import * > to > import bullet > > In your bullet file, i appended a line at the end that reads simply, > > bullets = [] > > Now in any file that you want, when you >>> import bullet > you can access bullet.bullets, and it will always be the same object. > This is what I do typically if i need something like this (like a > shared physics world or sound system access). > > Anyway, best of luck > > On Jun 7, 6:13 pm, GTM9 <[email protected]> wrote: > > > Hello everyone! Pardon me for getting right to the point; I'm a bit > > frustrated right now >.< > > (I'm kind of new to groups. I'm sure I've made this post twice, but I > > can't see them. I'm posting this from the "+ new post" in the "Home" > > page instead of in the "Discussions" page). > > > My first game with pyglet 1.1.3 is nicknamed Ship Showdown where two > > players fight each other and the first one to go down loses. I made > > the classes: > > > - ShipSprite > > - Ship > > - HUD > > - BulletSprite > > - Bullet > > > Finally I put all of them together and made the game work fine. > > > Stage 2: I focused on multiple scenes (Menu, Config, Game). For easier > > organization, I built the following classes to handle the game and > > scenes: > > > - Scene_Base > > - Game > > > Game sub-classes from pyglet.window.Window and handles the > > initialization, update and disposal of the currently running scene. > > > Then I made scenes subclassing from Scene_Base: > > > - Scene_Menu (the initial menu) > > - Scene_PreStart (players configure their ships) > > - Scene_Game (the actual game scene) > > > Now, the game runs fine but when the player returns to Scene_Menu > > after ending the game and starts the game again, I get an error > > "NoneType object has no attribute anchor_x" in the pygame Sprite > > class. The cause (as I understand it) is referencing a non-existing > > image (AbstractImage to be precise). I concluded it's a problem with > > managing the resources (now I have doubts, though). > > > So I tried loading the image everytime it is needed, I tried using the > > pyglet.resource module for loading images instead of > > pyglet.image.load, nothing works. > > > Here's the link to the source and required resources: > > >http://www.sendspace.com/file/0dbxnw > > > Could someone please help me fix the problem? Also, I would appreciate > > any suggestions on improving the semantics in any way possible. > > > Thank you! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
