Monthly Archives: January 2011

Lua – Guess My Number

I was messing around with Lua tonight, and as a basic exercise threw together a Guess My Number game. Unfortunately, doesn’t have syntax highlighting for Lua. C’est la vie!

I also learned that the first number you grab from math.random() may not be properly randomized after seeding. Running my code in the interpreter generated 36 five times in a row as the answer, which clued me in to this 🙂 Calling math.random() once after seeding seems to fix it, though.

-- Guess My Number
-- Author: Zachary Hoefler

-- Generate a random number
math.randomseed( os.time() )
math.random(); -- make sure first number is actually randomized (some implementations
               -- require this, but it doesn't break ones that don't)
local THE_NUMBER = math.random(1,100) -- generates a number from 1 to 100, inclusive

-- Welcome the user
print("Guess My Number, by Zach Hoefler")

local guess = nil -- explicitly declared to make it local
while (guess ~= THE_NUMBER) do
   -- prompt for a guess; use io.write() so there's no newline after the prompt
   io.write("Please enter a guess from 1-100: ");
   guess ="*number")

   -- Compare to the correct number
   if guess > THE_NUMBER then
      print("You guessed too high!")
   elseif guess < THE_NUMBER then
      print("You guessed too low!")
-- Number was guessed correctly
assert(guess == THE_NUMBER)

-- Congratulate the user
print("Congratulations, you guessed correctly!")

Strictly speaking, I could’ve used repeat-until instead of while, but the while loop felt a bit more readable.


Mid-winter Madness

With a combination of getting sick, winter quarter midterms, and lots of classwork, things have been a bit hectic! Regardless, though, some exciting things are going on at RIT.

Upcoming Events

  • Global Game Jam is coming up soon! Taking place Jan 28th-30th, participants break up into teams and work hard to crank out a completed game in a short time. I’ve signed up for this year’s event – it should be exciting!
  • Game Developers Conference is looming on the horizon. It’s quite expensive, but I plan to attend this year if at all possible. Although I was not lucky enough to snag a volunteer position to help pay for it, I’m hoping to be one of the lucky winners of the IGDA scholarship.

Current News

  • I’ve rewritten and reformatted my résumé pretty thoroughly. I like the new version quite a bit more, but I’m going to run it by a few people before posting it up here. This is step one in an overall plan to start working harder toward co-ops and internships 🙂
  • I’ve started to look into DirectX a bit, but I haven’t dived too deep into it just yet. Although in retrospect I should have expected it, I was quite surprised to see how tied into Win32 programming it is. I’m quite fortunate to have had a great C++ class; being exposed to calling conventions and the like beforehand has made figuring things out with DirectX a lot easier.