Monday, September 23, 2013

[HobbyRPG] tolua++ and menus!

This is turning into some sort of development blog, but from my perspective. Anyway, since LUA and UI were pretty big stuff we intend to add for this sprint, progress was seemingly slow due to time needed to research. I almost went into a huge hole of creating our own UI system but Dom managed to save me by just looking up cocos2d documentation -_-. I think when I figured that I could reinvent the wheel, I would just go ahead and do it without consulting Google or look for existing implementations.
Anyway, a not-so-glamorous progress to motivate ourselves!


For those who can't see the changes, I have neatly boxed them in red, since they are all code-based changes. Dom already told me a bit on how he intends me to use the UI, so I'll work on it once I can find better art. I'll try to follow his idea lol. 

LUA binding is a bitch. Well, it isn't once you know what's happening, but when you have no idea wtf is LUA, it's a bitch. cocos2d-x comes with tolua++ support, and I had no idea what that meant until I spent a couple of hours reading its online reference before I sneezed myself to bed on Saturday night. I felt super terrible yesterday, so terrible that I gave up on implementing it. Today I sneezed less, so I managed to get it working with a few good guesses. 

The documentation online for tolua++ is pretty heavy read for those who don't understand what's going on. Examples and tutorials are almost non-existent; in fact, the best tutorials I found were in Chinese or in Japanese. I totally gave up on the Chinese one. The Japanese one is easier to understand thanks to the existence of katakana. After seeing a few code snippets here and there, I finally figured it out. 

In a gist, tolua++ basically takes in a .pkg or .h file and generate a .cpp file with a function for you to call in your program. Then you just grab the lua state in your program (by right from tolua++.h, cocos2d-x has a wrapper around it) and throw it into the function that tolua++ gave you. I'm too lazy to explain in detail, but here's some poorly made step by step screenshots on how to expose a class to LUA:

First, get tolua++ to run on command line! Download the tolua++ executable and let adjust your Environment Settings' PATH variable to point to it. You know it's working when you open your command line and type "tolua++". The help page will appear:


Go to your project's root and create a .pkg file like so. Note that it looks almost like your .h file. These are the functions you want to expose. 


I must emphasize that the file included in the $cfile line MUST be accessible from the .pkg file's location. If not, tolua++ will complain.  Finally, just run tolua++: 


And voila, if there's no errors, you should magically have a file that looks something like below. If there are errors, well, just try to resolve them. Remember to Google for help (when in doubt, just Google the whole error message).


Add this to your IDE and pray that it works. If it doesn't, you screwed up somewhere in the .pkg file. If you have trouble, remember to Google, ask stackoverflow.com, attempt to find the answer in tolua++'s online documentation and/or actually try to figure out and guess how tolua++ binds your C++ code (it's not THAT magical). 

Moving on, the red box is the function you should be interested in. Simply call this function in your program and pass the lua_state in. The next screenshot is a cocos2d-x example since they have a wrapper: 

And now, when I run my script it works! (script is in first screenshot).

After you have successfully done this, the entire online tolua++ documentation will suddenly make sense! *gasp*





Wednesday, September 11, 2013

[HobbyRPG] And it has began!

Remember the RPG game I wanted to make?


It took some time, but finally Dominic and I have something visible up ^_^.

This is using the awesome cocos2d-x and my native language C++.  This project is probably going to be very slow since we agreed not to think about monetizing or selling it, and use it as a side project to create the RPG we want to make, which is great since there is no pressure. We can't guarantee if we will get burnt out at some point, but so far progress has been really fun for us!

Honestly, coming out of Digipen showed me how much I really wanted to make an RPG. After over 5 years in studying game development, I have only managed to create a simple text-based RPG game, which was a fun experience. Unfortunately, RPGs are extremely tedious to get it right, so it was not exactly a viable option as a school project, or even for a game you want to sell. Over the past decade, we have only seen the RPG genre decline and decline, leaving only a handful 'good' ones which were mostly cult hits. Hmm, not exactly a good genre to throw money into.

With this, hopefully when we go into design, I can attempt to return to my daydreaming story-writing days. I used to write tons of stories and other crap for fun, but that was easily a decade ago before I picked up programming and pursued to have a sciences foundation, easily obliterating my story-telling abilities and also my English. I can also go back to using Fruity Loops (which is now a full fledged...thing!) and fall onto my rusty music background to create sounds though I have much less hope of that succeeding. 

This project has sooooo much to be done, but it's so fun making each component work. Right now we are still working on the overworld system and already have animations, input and collision done. We also went to excel and write a macro to export stats into .csv files to reading into the game. 


What I like about this project is that it keeps my game development skills sharp, since I am not really doing development as much in my company.  We are also able to put into place what we have learn in our companies into this project, so it is a good learning experience so far.