Re: I want to lirn pithon but pithon doesn't want me to do so

Python will complain.  You need to learn not to do that.  It's very bad practice.  Most other languages will complain too, and I'm surprised it works in BGT.

There is an idea in programming called the single responsibility principle.  It means that each thing in your program should be responsible for one sort of thing.  In general, issues around circular dependencies, the name for the sort of problem you're describing, come up from not following it.  Put another way it's a symptom, not the cause.  You need to get good at learning how to use modules.  To give you an example, let's say I'm writing BK3.  I might have the following modules:

sound: Knows how to play sound files, either panned or as background music.  Offers this through a SoundEngine class.

Map: Knows how to store tiles in some sort of big array. Knows how to read this array from disk.  Knows how to write this array to disk.  Offers a Map class to do all of this.

Camera: Offers a class which takes a sound.SoundEngine and a map.Map.  Has some methods that get called when keys are pressed.  Knows how to play the camera sounds.

Physics: Takes a Map. Offers a PhysicsEngine class and a PhysicsBase class. You inherit from PhysicsBase to give an object position and velocity, and you register them with PhysicsEngine.  PhysicsEngine will call functions you provide or give you lists of events, but it doesn't know how to play sounds itself.

Level: offers a Level class.  It knows how to read a level definition from disk, load the map, load the objects in the level.  it's also a somewhat reasonable place to put code that connects events from the physics engine to sound.

game_loop: Offers a function run_game_loop, which knows how to run the game loop, start up Level, and route keyboard events to appropriate functions on various things.

main: Checks for updates, checks for authorization, etc. Figures out where the levels are on disk.  Generally does setup.  Then starts game_loop.

Obviously you're not at the point of being able to think about projects this big and this seems like a lot.  But what I just got is a pretty long list.  For example I can open a Python shell and test physics or maps by importing them.  When I'm working on sound, physics, or map I don't have to think about the rest of the game.  When I'm working on the higher level pieces like camera or level, I only have to think about the public API of physics, sound, and map, and I don't have to remember how they work internally.  If I want I can bring in unit testing stuff to test some of it in an automated fashion.  When I get bugs, usually I can narrow them down to a module rather than thinking about the whole program all at once.  Many of those example modules don't even import each other in the first place.

And yes, it also eliminates the circular dependency problem.  Which is important.  But compared to making me able to even write really big projects in the first place, solving that problem is kind of beside the point.  Unfortunately BGT doesn't even have a proper module system, and doesn't spend any time talking about arranging your code to be maintainable, so here we are.

Your brain is like a computer in the sense that you have finite amounts of memory to shove details about your code in.  People aren't good at thinking about programming.  Code organization is how you make up for those two fundamental problems of biology.  It doesn't matter how good you are, if you don't organize code well you'll hit a ceiling you can't get past, and it will be hundreds or thousands of times smaller than where you could be if you did learn to organize code.  You can disregard this stuff only for really small projects.  Many people do, and then wonder why they're stuck.  Otherwise, knowing how to split things up so that you only have to think about a little bit at a time is the difference between a finished large project and literally never getting to the point where it runs.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector

Reply via email to