Although the things covered in this tutorial are not hard to do, I wouldn't suggest using Firebase to anyone who's not familiar with Construct 2.
First, you need to get a Firebase account. Go to http://firebase.com and sign up with a Google account. Then you can create an app: the URL you set here will be the way you access your data from Construct 2.
To use Firebase, you need to download the plugins from RexRainbow. Luckily, Rex made lots of different plugins to suit your needs. Of course almost all of Firebase's functionality could be unleashed with just the Core plugin, but the rest make it easier to do certain things, for example make a leaderboard or a counter. I recommend getting the following plugins:
Core - http://c2rexplugins.weebly.com/rex_firebase.html
Auth - http://c2rexplugins.weebly.com/rex_firebase_authentication.html
Itemtable - http://c2rexplugins.weebly.com/rex_firebase_itemtable.html
Of course you can always get any more of them at http://c2rexplugins.weebly.com/
After you have installed these plugins, put them in your project, and in the properties tab you need to individually paste your App URL into every plugin's properties. In the
So you're done everything so far? Great. Using it won't be hard. I'll be covering the usage of the Itemtable plugin, since I think that has the most potential compared to how easy it is to use. Writing into your database is really easy. What I think is hard is figuring out how you want to organize things. You see Firebase uses the JSON format, and saves data that way. It doesn't have tables of data, and I find it harder to understand this way. For the purpose of this tutorial, we are going to make a simple database like this:
key2: different value
This, by the way, is a good representation of how Firebase stores everything. You can always organize things by having multiple levels of parents. To only have one level, just like in the example, you need to set the ItemTable object's Sub domain property to nothing. This will eliminate the first layer.
To write to your database with the Itemtable plugin, you use the Prepare: Set value action, then Save: save. In Prepare: Set value, you can set the key1 and the value from the example you can see above. In the Save: save, the only thing you really need to worry about is the itemID, which you will see as the parent in the example. If you want to set multiple items at once, you can add another Prepare: Set value. This is how it will look like in Constuct 2:
Open full size image
And this is the result in Firebase:
Open full size image
The easiest way to read things with the Itemtable plugin is to just have it download everything from the database, and filter it by itemID locally. Of course if the database is too big, you may have to try a different technique. Now to do take the easy route, just put a Load: Load all action somewhere BEFORE the time you want the data. It doesn't have to be on start of the layout, but just keep in mind that this download takes at least 0.1 second. You should set a tag, something like "all" or "main". If you need the data as fast as possible, use the Load: On load complete event. Use the ItemTable.At expression to get the value associated with a certain key. For example, if you want to get the value associated with key2 from the example above, you use ItemTable.At("parent", "key2").
Open full size image
First of all, thank you for reading. Thanks to RexRainbow for making these awesome plugins. Thanks to Firebase for offering this service for free for everyone. I hope that this tutorial has helped you make great games and if you have any questions, feel free to leave a comment.
Unlock your full gamedev potential
Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!
Plus, it's got a lot of additional features that will help you save time and make more impressive games!