Game Maker Developing Android Extension – Part 1

This tutorial covers the basics of Game Maker Android Extension development. With this tutorial, you’ll learn how to pass data between Java extension and GML.

This tutorial is created for beginners with beginner/intermediate programming knowledge. It may get boring reading all the instructions.

Introduction

All Android extensions for Game Maker uses Java programming language. If you are a newbie, or have no Java knowledge: Don’t worry! You’ll get used to it over time. There are also certain limitations that you must adapt yourself into. There’s a good information page for this, you can check it here.

This tutorial includes special tips and strategies for creating Android extensions.

Preparation

First of all, everything begins with CREATE EXTENSION. Head over the Extensions tab in GMS menu and select Create Extension.

This will open up a new screen, allows you to set versions of your extension, or change things. In this screen, we will select;

  • Copies To : Android & Amazon Fire
  • Extra Platforms : Android

And right click under Resources: area and Add Placeholder > Add Generic Placeholder. Here I’ve created MyExtension.ext

When you select Extra Platforms > Android, there will be another window presented to us. You can call it Android Extension HQ as we’ll do our tasks within there.

Great care must be taken to write Class Name carefully as we’ll need that in a moment. I’ll detail this window in second part of this tutorial. For now write your own class name, and save the project(CTRL + S).

This part is very important and you must follow the steps carefully!

Create a folder in your Desktop, name the folder same as your Class Name. Open a text file inside this folder and rename the file completely with your Class Name.java

Now we will simply transfer this file to Game Maker. Head over to the Extension Android Properties window(Android Extension HQ) and select Add Source and select your folder in your Desktop.

My memes folder is big, yea 😀

Now finally we can start making our Extension. Right click to your extension under the Extensions menu and select Open In Explorer.

Your extension will be under AndroidSource > Java > yourextension(or which name you choose).java. Other folders here has importance too, but not for now.

Now we are ready building our own extension. Remember that this is the file that you’ll be changing when you’re making your extension. You can now delete the folder and file you created in your Desktop. You can open this file with notepad, or you can use better tools such as Sublime Text. I use Sublime Text and it works perfectly.

Let’s Start Coding

If you have no Java background, you may find this process a bit hard, but don’t worry. It’ll get easier.

So, like in Game Maker, we can create functions that can take arguments and return values, or we can trigger Social Async Event(in Game Maker) and send data asynchronously to Game Maker.

There are some tools provided by Yoyogames to make our extensions. We’ll start coding our extension by including our classical package. Be noticed that they’re essential and should be used in every extension.

package ${YYAndroidPackageName};

//Game Maker Studio 2 Packages
import ${YYAndroidPackageName}.R;
import com.yoyogames.runner.RunnerJNILib;
import ${YYAndroidPackageName}.RunnerActivity;
What is 'com.yoyogames.runner.RunnerJNILib'?
This is the library that sends data to Game Maker via Social Async Events. You know, when you get something in Game Maker with async_load[? “id”] etc.. this is the agent that handles the task.
For using external libraries(Firebase for example), we include their respective libraries. We’ll discuss that in another part.

We will continue by creating our class. A class in java is like one single script in Game Maker. We will put everything we code inside it’s brackets.

public class thisclassnameisimportant extends RunnerActivity {
///... Our code
///.. Our code
}

Now, this part do include more of a Java lesson, but since this is the part 1, we will go with something easier. Let’s create a simple mathematical function.

Creating a Simple Returning Function

Game Maker only allows you to pass String or Double data type. Double is basically “real” in Game Maker. Be noticed that we must also declare arguments’ data types unlike Game Maker. public + double(returning value’s data type) + addNumber(function’s name) + double argument0(argument0 that’ll be coming from Game Maker and it’s data type) …
public class thisclassnameisimportant extends RunnerActivity {

//public double addNumber > returns a double data type
//public String addNumber > returns a string data type
//public void addNumber > returns nothing!

public double addNumber(double argument0, double argument1) {

return argument0 + argument1;
//Java algebra is the same as Game Maker

}

}

So what we have created is a function that adds two values and returns that. Save the file now and head back to Game Maker Studio.

Remember that we created a generic placeholder under resources menu. Now we can go there.

Simply right click under Functions area and Add Function. The second window will be opened. Make sure to write the SAME NAME as you wrote in the java file in External Name field. You can add or remove Arguments by clicking plus(+) or minus(-) icons.

  • Since we returned a Double data type, ReturnType must be double!
  • Since both our arguments are declared as double in the Java file, we must change their data types to double as well.

Congratulations! You have your first extension ready! If you go create an object in your game and write;

var hello = AddNumber(5,5);
show_debug_message(hello);

It will display 10 in the log console.

Returning Values with Social Async Event

It is exactly the same as above, except we will use some special functions to do that. First, we will declare a static final int value(Yes that’s too long to hear). It actually represents a number 70, which is used for Social Async Events. You should declare it outside of a function(Preferably at the beginning). We will continue creating a function addNumber. Looks so similar to Game Maker, right? At least a bit. We will create a DS_MAP in Java and populate it.

public class thisclassnameisimportant extends RunnerActivity {

private static final int EVENT_OTHER_SOCIAL = 70;

public void addNumber(double argument0, double argument1) {
//Java algebra is the same as Game Maker

int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);

RunnerJNILib.DsMapAddDouble(dsMapIndex, "result", argument0 + argument1);

RunnerJNILib.DsMapAddDouble(dsMapIndex, "hello", "How are you?");

RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);

}

}
  • RunnerJNILib.jCreateDsMap : Creates a Map(It is really the same as ds_map)
  • RunnerJNILib.DsMapAddDouble : Adds a double data typed value in our map.
  • RunnerJNILib.DsMapAddString : Adds a string data typed value in our map.
  • RunnerJNILib.CreateAsynEventWithDSMap : Sends our map to Game Maker.

Executing this code will trigger Social Async Event in Game Maker populated with

var result, message;
result = async_load[? "result"];
message = async_load[? "hello"];

And that’s it, you’re now familiar with creating Game Maker Android extensions. In the second tutorial, we will go deeper into how to structure our data and eventually you’ll be able to import 3rd party SDKs into your apps.

Share

Marty

Truely speaking, I don't know what am I doing most of the time.

Leave a Reply