Hey everyone!
Long story short, I've dabbled in programming for many many years. I was most proficient with Blitzmax and a BASIC variant for PalmOS back in the day but I was never super serious. For example, I conceptually understand OOP and think it's very logical but in actual practice it used to give me a lot of trouble and I was more comfortable with procedural.
Anyway, its been years since I've done anything and Pythonista seemed like an attractive way to try to jump back into things (I have a soft spot for mobile platforms). There are very noticeable differences between Python and BASIC, and a lot of other stuff that's very similar overall. But I'm trying to slog through and do different things and there's one that I just can't seem to nail:
Initially I just wanted to create a grid (2D array, or however you'd prefer to call it) which could store an integer at each gridpoint and could be dynamically sized and created using loops (instead of typing out each list-item by hand). Something that could hypothetically be accessed with something like:
mygrid [2, 5] = 5
print mygrid [2, 5]
I actually basically managed to achieve that particular goal using numpy, with the following:
mygrid = numpy.zeros((heightvariable, widthvariable))
And from there I could change and access the integer using the first bit of code.
Next I wanted to take it a step further and create a similar grid, but instead of each gridpoint being an integer, I wanted to make each an instance of an object. I haven't had a clue how to do this and tutorials/info online hasn't seemed to help much so I've been trying to do it myself (while trying to get more comfortable with classes). To simplify it I've been starting out with trying to just create one row (list) of object instances and I haven't gotten anything working yet.
For reference: I'm loosely imagining/shooting for this as being a tilemap for [insert generic game here]. I'll be using the Scene module for output. And I'm looking for just the most barebones way to create a map object and then populate it with tiles which are arranged in rows/columns in a way that they can be individually accessed.
For additional reference: part of my problem I think has been syntax/code arrangement: I keep bumping into scope and argument issues, which I more or less understand but I'm not always sure how it wants me to resolve them. For example, in the following code:
class MyScene(scene.Scene):
themap = Map()
class Map(object):
#blahblahblah
I get the error 'Map' is not defined (NameError). So I tried creating my map instance in the update() or init() methods of the scene (so that they're created at the start) but when I later tried to USE the map instance, I got the error global name 'mymap' is not defined (NameError). So there's a scope issue where I have no clue where I'm supposed to create it and how I'm supposed to make it accessible at least in the rest of the class.
I apologize for putting so much in here. I realize it's a lot of basic stuff, I've been trying to read as much as I can but I think I'll find it more helpful being able to have an actual dialog with someone. I appreciate any help anyone can give!
Cheers,
Nate