Trade and Dominion: Moving armies

It’s been a long while since I said anything about this project, but I have been working on it. Mainly I’ve been feeling my way around Javascript, Ruby on Rails, and now also SQL; web programming is new to me, as are databases. I’m starting to get a feel for it now, though.

My old problems with random hangs seem to have been caused by a trailing quotation mark in my rhtml code, making trouble somewhere in the interface between Rails and Javascript. One good thing about a formal compilation step, even if it is a bit slow: The compiler will yell at you for syntax errors. Agile development is possibly a great step forward; syntax errors causing untraceable random crashes is not.

However, all’s well now and I have a full game loop: That is to say, the player can click on the map to bring up a list of the armies in each city, can order the armies to move to neighbouring cities, and can click ‘submit’ for his orders to be executed. And the armies do move, and the database does get updated, and it is evening and morning the second day. Not very exciting as games go, by any means – the armies don’t fight, or anything, they just move around – but there’s a lot of backend stuff set up that I didn’t have before. What’s more, I now actually understand (at some level) all this database stuff, and (complaints about syntax checking aside) am beginning to feel how powerful Rails really is. Coding even this basic functionality by hand as SQL queries would have taken me weeks.

A minor problem is that there doesn’t seem to be a way for an object of a given class to point to a collection of the same class, only to different classes. You can do has_one, eg


class Foo
has_one :foo
end

but not has_many:


class Foo
has_many :foos, :through => association
end

because there is no way to set the foreign keys in the join table properly. :through will by default guess that the foreign key is foo_id, and then what should it set the other key to? I can’t figure out how to specify this when both targets are the same class. So this has to be coded by hand, or at least I had to do so. Perhaps there is a clever way. But this is a minor complaint.

Advertisements

Leave a comment

Filed under Trade and Dominion

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s