Did you ever wanted to use Ruby and C# together in the .Net environment? With IronRuby it’s possible, and fortunately I thought of sharing this quickstart guide with you. I assume you’re using .Net 4.0. I’m using SharpDevelop but the steps should be the same for Visual Studio.
Here are the quick steps to install IronRuby inside .Net
We’re now ready to code our first Hello World program using IronRuby inside our ‘program.cs’ file (it was automatically created for us when we created our console solution). I’ll try to write as few lines as possible to keep the startup tutorial very simple:
I assume you already have basic knowledge of C# and .Net (and Ruby!), so to make a long story very short, we’ve implicitly created a variable called engine that contain the ruby engine, then we used it to execute lines of code in which a ruby class was written on the fly and it’s executed. P.S: It’s important not to forget that C# is a static typed language and Ruby is dynamic and weakly typed language.
For better clarity, our ruby code can be executed from a ruby file. For example, let’s create a ruby file named Hello_Class_File.rb and paste the following code inside it:
And now, in our C# file:
So, how would we assign a ruby object to a C# object? First let’s bring changes to our ruby file:
Now let’s bring a few minor changes to our C# file:
So that’s it, we can use C# and Ruby together. I’ll think of future tutorials. For example, one really bad thing right now is the complete lack of Intellisense with IronRuby.
*** Sorry for the bad code formatting, I’ll have to install a proper wordpress plugin when I find some more free time!
One major issue I noticed in RM communities is how coders overdo it when it’s time to add a new feature in the scripting section of the game engine. The explanation for this is surely because very few coders had spent enough time to make a proper dissection of the default code written by Enterbrain, which I must admit is a real mess and is terribly overwhelming to decipher. However when you get used to it you can make quick changes without ending with hundreds of extra lines of code.
I have seen several scripts that allow to skip the opening screen during play-time and all of them require way too much changes in the default code, therefore they’re a bit confusing to install and increase the risk of compatibility issues with other future scripts. So my #1 rule is to keep things as much simple as possible. So here’s the simplest way to do it.
Go in the scripting section of the engine, select the SceneManager module and find:
# * Get First Scene Class
$BTEST ? Scene_Battle : Scene_Title
Replace it with:
# * Get First Scene Class
$BTEST ? Scene_Battle : Scene_Map
See? Only three lines of code had to be changed to make this miracle happen!
Important notice. Gamezopher will soon be completely rebooted with new contents. This blog will no longer focus on my personal game developments or my personal life. Other blogs will gradually be customized to serve those purposes. Discussing game development in general, my ongoing game projects, my personal life and miscellaneous topics under the same blog wasn’t a good idea anyway.
Gamezopher was first imagined around 2005 and was meant to be a website on game development and game technologies in general. It’s about time I give the name its true meaning. It doesn’t mean it will become a large website, I greatly lack of time in my life, but at least I can share some parts of my knowledge and experiences with the crowd here. I have already written several articles on diverse subjects (such RPG Maker tutorials), I was just waiting a good time to publish them.
Please find my other blogs [here].