Booyah!! Success in Lua!

luastate.JPGI’m quite proud of this. And it has some wide implications in-so-far as Renevatio development…

What you’re looking at is a scripted sequence executing within TimeWaster (Yes! I am still working on that thingie). The Lua scripts are being called from C++ thanks to tolua++, which generated a C++ header file with the calls I needed (after some minor modifications and a wrestling match with G++’s linker). The Lua classes call the Singleton game states, also a bit of technology that I planned on using in Renevatio. The fact that the Lua scripts are able to intermingle with existing singleton object members(non-static members I might add) provides a breeding ground for a lot of the material I planned on incorporating. TimeWaster essentially just graduated to a proof of concept application.

Though, I do plan on still creating an actual game with it.

Good ol’ Winderz

It seems that every few months or so, my Windows machines… no matter how well I try to upkeep them… all end up getting reformatted and reinstalled. I don’t care what flavor of Windows I was using: 2000, XP, whatever. I’m sure I’ll have the same issues with Vista if/when/pfft I ever switch over to it (**chuckles**). But after about 4 months, I’ll notice the box begins to run a bit slower. After 5 months, I’ll be annoyed with some system processes that just won’t turn off, no matter how many times I disable them in services or the registry. At 6 months I’ve usually had at least one explorer error. By then, it’s usually burning time.

That’s not to say that I don’t have the same issue in Linux, but no where near as severe. My Ubuntu box has been doing well, even though I’m annoyed as all get-out with Gnome (not Ubuntu’s fault). It’s a lot easier, though, to get annoyed with one particular program that’s acting up in top and just rf -rf whatever’s causing it (not literally). Maybe I’m just better at managing the Linux FS than Windows. Maybe my laptop just has a program that scans my fingerprints and sees if it can detect any Linux residue on them, because I know others don’t have this issue. Ryan takes every advantage he can to call me a “n00b”, and Windows is the weak point. Maybe I don’t know the special password that makes Windows NOT act like there’s some phantom slowly dripping superglue into the spinning gears that drives the OS; maybe I don’t know the proper command-line key for kicking the gerbal running on the Windows kernel spinwheel in the ass. But at some point in my “Windows Experience”, I will tell it to launch FireFox, walk away to get a drink and do my taxes, and by the time I get back, it may or may not be open. That’s unacceptable.

So mark your calendars. Six months from now, I’m sure I’ll be hosing another perfectly good Windows installation. Think I may rip an image of my laptop’s hard drives this time, though. Maybe that’ll speed the process next time.

In True College Tradition. . .

cubic1271 presents the project specification as submitted less than an hour before the deadline!

For my project, after much consideration of many ideas and the like, I’m thinking I’m going to just do the project I was doing for the 40 hour competition, except that I’m going to take more than 40 hours to do it.

In other words, standard RTS. Build buildings, target stuff. Etc. If you’ve ever played netstorm, that’s essentially what I’m shooting for, except tron-ish and space-ish. If you haven’t ever played netstorm, you should go download it and give it a try. It’s a really cool game, and last time I checked was a free download.

Anyway, that’s about it. Need to go finish homework now. More to come as I get artwork.

Poking at Lua

Lua’s a simple, light-weight scripting language that supposedly is pretty easy to hook into C++. And that’s true… provided you meet a few conditions, such as static member methods if using lua_register() inside a class. While I won’t go into too many details at the moment concerning that (since I’m still researching them), I can say that it works pretty darn well for linking methods outside of classes (which are inheritantly pseudo-static anyway).

I will give it this much: Lua is extremely easy to build, especially in a GCC or Visual C++ environment. To install it in Visual C++, simply create a new project and import every *.h and *.c file in the source directory into the project except print.c and one other (which elludes me, but the compile process will flag it). In VC, you’ll need to compile the project as a DLL and as a static LIB file. I then copied these into C:\Program Files\lua\lib and linked it into Visual C++ Express Edition. Then copy every header file into a new includes directory in the same lua location, add it to VC EE, and done.

The Lua package is intended for a C environment, but C++ support is easily done by including the extern‘ed wrapper, “lua.hpp”. From there, to get Lua up and running in C++, there are only a few needed calls:

#include <stdio.h>
#include <lua.hpp>

int myFunction( lua_State *state )
{
  printf("\tLUA passed argument: %s", lua_tostring(state,-1) );
  lua_pushnumber(state,0);
  return 1;
}

int main()
{
  //open the Lua virtual machine
  luaState *vm = lua_open();

  //register the c++ function
  lua_register( vm, "l_function", myFunction );

  //call our Lua script (can be pre-compiled)
  luaL_dofile(vm, "./script");

  //shut down the lua virtual machine
  lua_close(vm);

  return 0;
}

To get this to compile in G++, simply pass it the “-llua” argument (NOTE: I haven’t needed -llualib or -lauxlib thus far in my Lua travels).

Next, we write up our Lua script to be used within this C++ app:

l_function( "argh" );

Compile this Lua script if you want with “luac -o script_compiled script_name“. Compile the C++ class, execute it, and you’re done.

Next up: registering a non-static function in Lua. At the moment, I’m playing with tolua++. More to follow.

Slight Change of Plans. . .

Well, this is probably going to cost me in the end, but I think I’ve decided that I’m going to drastically revise the gameplay for my game. Why? Well, I learned two major things from the 24 hour game thingy:

1) If a game is too complicated, it’s boring. Yes, that’s right. Most people don’t like spending an hour figuring out what the hell’s going on. Even if the game itself is fun, if you can’t get people hooked quickly, they won’t keep playing.

2) What I have planned is probably a bit more than I can get accomplished and get polished within the next 35 hours. While I do believe myself to be a competent programmer, there are some things I just don’t think I can do. The game in its entirety within the next 35 hours is one of them.

I have the new design sketched up and planned out, so gonna start that soon. We’ll see what happens. . .