Some progress towards multithreading


I’ve made some good progress today. I’ve got a super basic new/load title screen that loads…well so far it only loads one new thread, but it will handle the two threads that I can think of right now, the GUI and Logic thread.

It’s been tough going to get to this point because I was really having trouble figuring out the proper module structure, but what I’ve done is kept most everything in the global space of each of the 10 or so modules I’ve got, and just use a ludicrous amounts of module.attribute calls, which means I do a lot of imports over from module import. I can’t see that being a good thing in the future, but for now it’s what I’ve got.

The project doesn’t have shooting, GUI beyond pygame or enemies yet, because the modules haven’t been fully updated yet, but so far it just looks like I’ve gotta keep renaming certain objects, which Wing makes crazy easy. I’d really like to take the time here to outline all the positives, but I really don’t have anything to compare it to, other than notepad 1. It’s got just about everything you’d need

Anyways, like I mentioned I need to update those other parts before I can start making forward progress. I imagine I’ll need to learn how to use Queues to properly sync my threads, but I’ll have to leave that for another time.

So what I’ve learned today is that globals do not need to be at the start of a function, despite what I used to think, imports are sort of tough to get right, but fairly easy once you get the hang of it, and that it still feels really good to see what you’ve made work, despite little visible change.

Module Management

In this post, I’m going to try and plan out my module layout. As it currently stands I’m only using and This is going to become something quite different, as I’m hoping to solve the namespace issue I’ve been having.

It started when I started using the popular if __name__ == ‘main’: format I decided I wanted to clean up all the initialization stuff into a particular function init()but that was not as easy as I had hoped for. In fact it broke my code enough that I am writing a post about it.

The issue is probably obvious to anyone but me, but I forgot how namespaces worked. That is, I forgot that even if you put a function in the top level of a module, all variables created therein are scoped to that function. So what that left me with, was a global scope that was free of any variable I had created in the init() function. So I took to reddit, as usual, to solve all my issues.

Luckily, the ever present user, eryksun, was around, along with others, and informed me that multiprocessing worked best with the Queue module and my two modules split up into smaller ones.

I figure that that would my scope issue because instead of just calling for example to get his name, I could call and get it, from any module that has imported objects. So this is going to mean for my code a slight rewrite, but more of a copy and paste sort of deal, with several changes to most calls in my entire two modules. Which aren’t that big, keep in mind. Maybe 1500 lines total, across and

Anyways, so far, my draft is this:

–          Main, which creates the two threads for logic and GUI2, which I’m going to drop the 2 from.

  • GUI is just going to be fed stats from logic and stats, but will also be able to change some of the stats it changes. I’m not sure how to do this just yet. I’m hoping someone will drop down from the heavens and show me.
  • Logic is going to be the main game logic behind most of everything. It’s going to draw on Tools, Objects, Items, Environment, and Stats so it’s going to import a few things.
    • Tools is going to be the module for most of the my math oriented stuff, also the function for handling images.
    • Objects is going to be the module for all the characters in the game. It will rely on AI for the NPCs. Have to decide whether the character components will be created there or not.
      • AI will be in charge of the AI patterns and such, when they get developed. Like I have previously written, I cannot get a handle on A* pathfinding. I’ve really tried though, it’s just not working.
    • Items is going to handle the items in the game. So all the drops and crap will be taken care of here.
    • Environment is will be where of the world information will be handled, so the world squares, backgrounds, that sort of thing.
    • Stats is going to be where the absolute plethora of statistics will be handled. This game will have an insane amount of stats, let me tell you what.

So there you go, a quick breakdown of what I’ve got in the works for now. It’s been a fun ride so far, for the most part. I hope it keeps going.

Looks like wordpress ate my formatting from msword which is a shame. I had all the module names styled as code.

Namespaces again.

So I’ve started using different modules for my squares project here and what I’ve ran into is namespace problems again. In my name == main I’ve got just the init() function, but that creates all the game objects under that function’s namespace, rather than global, like it used to be when I had everything in my name == main instead of in a nice function.

Perhaps instead of a all-encompassing int() function I create functions that return objects and use those. I’m not sure.

Have to make a text tagging tool

This tool is going to be for my story book application.

What it’s going to do is ask for a project file or make a new one, and all that file is is a preset set of tags.

Then once you open the very simple editor, you’re going to be able to write text in premade tags, dictated by the project file, which will be saved in a format which could be parsed by a program.

I’m not sure but I’m pretty sure this is exactly what xml is but I really have no idea, so I’m just forging through!

If you know of a kind of program I’m looking for though, lemme know.


Also, I’ve started using my Twitter (@tankorsmash) more so hopefully that will help me with things. I’m pretty new to it, so I’ll probably just use hashtags for everything. I’m using Plume for android. It’s pretty neat.