This entry is part 3 of 9 in the series Artificial Galaxies

Lastly, to complete the introduction of the process, we’ll need a Civilization object to cram our species into. We’ll keep it basic for now, with name, type of government and species type. The Civilization object will be pretty basic but we can definitely finagle some more attributes into it down the road (and boy howdy do I plan to!)

 

 

 

 

So we’ll begin the awesome goodness of creating a bunch of objects and making sense of the whole thing. So first, we’ll instantiate the Civilization object and fill it with some info on the Species and government type and name.

Let’s begin. Download the file. Unzip it to wherever  you want and open it on up. It should look like the below:

 

 

 

 

 

 

 

Don’t panic, one of those files we didn’t discuss, but we will. Matter of fact, let’s discuss it right now. The one named ‘government_types.json’ is a JSON list of various government types I grabbed as an example from David A. Rozansky’s site since he had a convenient list of them. Of course, you’re welcome to add to the list, remove, etc. but there’s a function you can see in Civilization.lua called Select_Random_Government. What that function does is go out to that file every time we create a new Civilization and assign a random government type to it. Random, to be sure, but we can always add more functionality down the road.

Open up the Civilization.lua file from under classes in your editor of choice.

Now mind you this is in Corona and not pure Lua. Pure Lua, we’d use the lfs and some JSON module I’m sure. I’ll get a pure Lua version uploaded soon, but in the meantime, you can ignore the Select_Random_Government function for now, and we’ll concentrate on the OOP aspect of the code.

So far, we only deal with two objects; the Species and Civilization objects. In main.lua we create the Civilization object first, which then in turn creates a Species and keeps track of it in itself:

Notice on line 8, THAT’S where we instantiate our Civilization object. We assign to the variable ‘myCivilization’ the Civilization object we’re instantiating. Then below, you can see we can use dot notation to start querying the data from that object. For now, it’s not super exciting, we have the following output from my test run:

But now that the foundation is laid, we can start gussying up these objects!
Here’s the code, simple as it is, if you want to take a look at it!
artificial galaxies 1

Series Navigation<< Designing a Species object and a Planet objectThe Star and Planet objects >>