Ubuntu: Change Hostname, or, Why is sudo so slow?

After installing Ubuntu, I decided that the name I gave my computer was not satisfactory. So, I followed this how-to, which explains that you can simply change it by editing the contents of the file
/etc/hostname
and restarting the computer.

After this change (I didn’t make the connection until later), any sudo command would take almost a minute to run, and give the error sudo: unable to resolve host <hostname>.

The resolution is that you can’t only edit this file. The file
/etc/hosts
must also be edited, so that 127.0.0.1 resolves to the new hostname you defined.

Immediately, sudo began working properly again.

Using compiled Lua with Moai SDK on OSX

Today I started taking a look at the Moai SDK for game development. It’s a game engine that uses Lua for scripting, without ever having to touch the C++ code underneath if you don’t want to.

A Moai application is actually just a set of .lua files that are fed into the moai executable (moai main.lua), which can be downloaded as a binary or as source with projects to build it on various platforms.

My first thought, rather than how to make a game or do anything interesting, of course, was how how to release a Moai game without distributing plaintext source (I’m not suggesting you shouldn’t, but that in some cases you might not want to). It turns out moai can take in compiled lua, as well.

Great. So I install lua with homebrew, compile with luac -o main main.lua, run moai main, and get this crap: -- main: bad header in precompiled chunk.

Turns out this is because the homebrew installation of lua is 64-bit, and moai is 32-bit, and they just don’t get along. In order to compile lua source properly for moai, you’ll need to download lua5.1.4 and compile it for 32-bit. I found the solution here, but I’ll reproduce it below as well.

  1. Download lua 5.1.4
  2. Unpack it, cd into that directory
  3. Modify src/Makefile by finding the lines
     macosx:
        $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"

    and changing them to

    macosx:
        $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX -arch i386" MYLIBS="-arch i386 -lreadline"
  4. cd src
  5. make macosx
  6. cd ..
  7. sudo make install (note, this will write to /usr/local/bin, which will overwrite any existing lua install)

Now you should have a version of lua such that your luac-compiled files will get along nicely with Moai!

-E

Playing Solitaire

I spent the evening writing a solitaire simulator. I’d suggest at least glancing over this article first so that it makes a little bit of sense.

Now, this may not be a version of solitaire you have ever played or heard of. I, however, have known it for as long as I can remember. My mother taught it to me at some point in my development, and I have used it as a pointless time waster ever since. It’s especially great when you are tired, because it takes absolutely no real thought.

Shuffle the deck.

Draw cards one at a time from the back of the deck, putting them on top into what I like to call the “play stack”.

The cards you pay attention to are the top card on the play stack, and the fourth one down. There are two rules:
1. If these two cards are the same suit, remove the two cards between them.

2. If they have the same value, then discard all four cards – the ones that share the value and the ones in between.

Rinse and repeat! You can do multiple discards per draw, so it’s fun when you get a nice chain reaction after a dry spell of no discards.

If you’re curious how that game turned out, whence I took the screenshots…

I ended up with two cards, not too bad!

So, of course somewhere along the line I realized that this would take no creativity to write into a computer program, considering there is no strategy, it is a simple reflex game. I wrote a simple javascript page to simulate playing many games, to gather statistics. The page is here!

I ran 10 million games, and found…
Win rate: 0.7%
Average cards left over: ~13

So, it looks like I can have a reasonable chance of winning if I play about 150 games. OK!

-E

Koans!

So, I found this site and it’s great.
http://sett.ociweb.com/sett/settJan2011.html#javascript-koans

It’s a set of sets of short exercises designed to introduce you to some of the quirks of a new language.

I blasted through the Javascript ones today. There could have been more, but it was quite fun.
Javascript Koans Github Page
Just go download the source and follow the instructions in the readme. These are definitely worth doing for anybody who wants a quick jump into Javascript!

-E

Creating an HTML5 Game, Part 1: The Objective

My most recent personal project has been creating a fully browser-native game written entirely in javascript. Considering I didn’t know javascript previously, it may be all new to you, but it’s definitely all new to me!

This first post will not be about javascript, but about setting the framework in place to begin work on this game.

Now, you can call me outdated, but my greatest inspiration comes from 2D SNES-era platformers and RPGs, so I’ll be using these as my design reference in these tutorials.

Games like these keep me warm at night.

The Objective

What I want out of this project is a framework, within which I can easily craft new levels, characters, and behaviors, without doing a whole lot of complicated coding. The features I want are as follows:

  • Pure javascript+HTML5 game, to run without any plugins or downloads on any HTML5-enabled browser.
  • Easy map and character making utilities, so that I never have to hardcode game assets.
  • Something fun to play!

Note:┬áIn general, I work by a design philosophy where I need to have something to play with to feel like I’m making progress. So, at every point in creating this game, I’ve got a working prototype, some of it rather hacked together. Cleaning things up and generalizing code comes later, when I need those features.

This post has the potential to get very long, so I’m going to break it up into quite a few parts, for my own sanity and yours.
Next topic: The Map.

-E

Hello, indeed

I’ve added an About Me page, and a Projects page. They’re both pretty simple, but it’s a start!

Hello world!

document.write(“Hello World”);
cout << “Hello World”;
println(“Hello World”);

It’s all the same to me.

-E