GameMaker error handling and capture

Does anyone know if there are any ways to capture and error when otherwise it would cause the game to stop. For example unknown variable errors. I want to capture them and run further code so that I can give out beta versions that will email me when an error has been found.
 

marasovec

Member
There is no way to do that. If a variable or an object is missing how can you continue running the game with that?
EDIT: You can check if a variable exists using "if variable != undefined"
 
Last edited:
I guess you could ignore the instruction but what I need is some way to have errors reported to me. Much like any other software out there.
 
C

CombatCalamity

Guest
There is a way, you just need to do them yourself. This is how all other softwares out there do it.

EDIT: You can check if a variable exists using "if variable != undefined"
You still need to initialize that variable too apparently.. Which means you can't just read a variable called 'iurniasueari' randomly and report that..


Anyway, if you want a painless solution to 'have all errors emailed to you' then no can do. Sorry.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I recently made an extension that does exactly this.
For undeclared variables specifically, you could check via variable_instance_exists, but that requires knowing which variables might not exist.
 

curato

Member
Yes I really think GML could really you a try catch finally statement. There are work arounds but it is fairly common in C which it gets much of its syntax and would simplify code sometimes. I don't find I miss it in GML as much as I would in other types of programing. GML is structured in a way that it avoids a lot of the ID-10-T errors one could usually make.
 
Thanks for the link to the extension. Curato. Undefined variable errors were just an example. I wanted to catch any error. It may be easier just to do everything manually. Thanks
 

Speederman

Member
I've just found a way of doing this on Android. The fact is that Game Maker uses ShowMessage function to show the error popup windows on Android. The trick is simple: you have to modify that function to do whatever you want with the message every time it is called and you've got it. It is not used for anything else (if I'm not wrong), so its message will always be an error. Anyway you can also check if the message contains the word 'ERROR' to be sure.

I'm using Game Analytics in my game (there's a free extension on the Marketplace) and it's extremely easy sending the error reports to it. This way you can track your player's issues in real time. This is what I've done:

Once you have installed and configured the Game Analytics extension, go to 'C:\ProgramData\GameMakerStudio2\Cache\runtimes\runtime-<your-version>\android\runner\ProjectFiles\src\main\java\com\yoyogames\runner\' and edit the file 'RunnerJNILib.java' with any plain text editor like notepad.

Add this line at the beginning of the file right below 'import ${YYAndroidPackageName}.RunnerActivity;':
Code:
import com.gameanalytics.sdk.*;
And now modify the ShowMessage function adding this line below 'final String sMesage = _message':
Code:
        GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
The full ShowMessage function should look like this:
Code:
    public static void ShowMessage(String _message ) {
        Log.i( "yoyo", "ShowMessage(\""+_message+"\")");
     
        final String sMessage = _message;
        GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
        final CountDownLatch latch = new CountDownLatch(1);
        RunnerActivity.ViewHandler.post( new Runnable() {
             public void run() {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ms_context);
                    builder.setMessage( sMessage)
                        .setCancelable(false)
                        .setPositiveButton( "OK", new DialogInterface.OnClickListener() {
                            public void onClick( DialogInterface dialog, int id ) {
                                latch.countDown();
                            }
                         });
                    AlertDialog alert  = builder.create();
                    alert.show();          
             }
        });
             
        try {
            latch.await();
        } catch( InterruptedException e ) {
            Thread.currentThread().interrupt();
        } // end catch
    } // end ShowMessage
And that's it! From now, all your error messages will go directly to your GA account, where you can track them. It's woth nothing that you'll have to modify 'RunnerJNILib.java' everytime you upgrade your GM, but they are just a couple of lines, so no worries...
 
Last edited:
you can do it by yourself without any extension. but it will be a hard work, but if you want to do your things very easy, buy or download what you need :)
 

FrostyCat

Redemption Seeker
you can do it by yourself without any extension. but it will be a hard work, but if you want to do your things very easy, buy or download what you need :)
Can you please NOT bump up old topics, especially with outdated, uninformed advice like that?

Capturing runtime errors is now built into GMS 2.3 with try-catch-finally and exception_unhandled_handler(). Not what I'd qualify as "hard work".
 
I've just found a way of doing this on Android. The fact is that Game Maker uses ShowMessage function to show the error popup windows on Android. The trick is simple: you have to modify that function to do whatever you want with the message every time it is called and you've got it. It is not used for anything else (if I'm not wrong), so its message will always be an error. Anyway you can also check if the message contains the word 'ERROR' to be sure.

I'm using Game Analytics in my game (there's a free extension on the Marketplace) and it's extremely easy sending the error reports to it. This way you can track your player's issues in real time. This is what I've done:

Once you have installed and configured the Game Analytics extension, go to 'C:\ProgramData\GameMakerStudio2\Cache\runtimes\runtime-<your-version>\android\runner\ProjectFiles\src\main\java\com\yoyogames\runner\' and edit the file 'RunnerJNILib.java' with any plain text editor like notepad.

Add this line at the beginning of the file right below 'import ${YYAndroidPackageName}.RunnerActivity;':
Code:
import com.gameanalytics.sdk.*;
And now modify the ShowMessage function adding this line below 'final String sMesage = _message':
Code:
        GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
The full ShowMessage function should look like this:
Code:
    public static void ShowMessage(String _message ) {
        Log.i( "yoyo", "ShowMessage(\""+_message+"\")");
    
        final String sMessage = _message;
        GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
        final CountDownLatch latch = new CountDownLatch(1);
        RunnerActivity.ViewHandler.post( new Runnable() {
             public void run() {
                    AlertDialog.Builder builder = new AlertDialog.Builder(ms_context);
                    builder.setMessage( sMessage)
                        .setCancelable(false)
                        .setPositiveButton( "OK", new DialogInterface.OnClickListener() {
                            public void onClick( DialogInterface dialog, int id ) {
                                latch.countDown();
                            }
                         });
                    AlertDialog alert  = builder.create();
                    alert.show();         
             }
        });
            
        try {
            latch.await();
        } catch( InterruptedException e ) {
            Thread.currentThread().interrupt();
        } // end catch
    } // end ShowMessage
And that's it! From now, all your error messages will go directly to your GA account, where you can track them. It's woth nothing that you'll have to modify 'RunnerJNILib.java' everytime you upgrade your GM, but they are just a couple of lines, so no worries...

Hi @Speederman, thanks a lot for this, exactly what I was just looking for!
Unfortunately, it doesn't work for me for some reason, although I tried using various variants of the "GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);" part - build still keeps failing. If you're still around this forum - do you know what the problem might be? This is the output I get:

GML:
> Task :com.brusgames.castlebuilder:compileDebugJavaWithJavac FAILED
F:\com.brusgames.castlebuilder\src\main\java\com\yoyogames\runner\RunnerJNILib.java:1297: error: cannot find symbol
    GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.GAErrorSeverityDebug, sMessage);
                                                           ^
  symbol:   variable GAErrorSeverityDebug
  location: class GAErrorSeverity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: F:\com.brusgames.castlebuilder\src\main\java\com\brusgames\castlebuilder\GooglePlayServicesExtension.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
I think it should be correct, I also checked with https://gameanalytics.com/docs/s/article/Android-SDK-Event-Tracking#Error-Events and everything seems ok, also tried reinstalling the GA extension... Thanks in advance for any suggestions!
 

Speederman

Member
Hi @Speederman, thanks a lot for this, exactly what I was just looking for!
Unfortunately, it doesn't work for me for some reason, although I tried using various variants of the "GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);" part - build still keeps failing. If you're still around this forum - do you know what the problem might be?
Hi! Sorry, but I don't know why this is happening to you... Anyway, have you seen the new error handling that comes built in GM since version 2.3? Take a look at the new exception_unhandled_handler function and so you can do it all within Game Maker without the need of modifying any java files.
 
Hi! Sorry, but I don't know why this is happening to you... Anyway, have you seen the new error handling that comes built in GM since version 2.3? Take a look at the new exception_unhandled_handler function and so you can do it all within Game Maker without the need of modifying any java files.
Thank you anyway! I was actually trying the exception_unhandled_handler function first, but it only works for me in Windows target, not on Android, for some reason. I can't even get the game to display any custom error message on Android, not sure why... But that's not related to your solution, I'll try to dig around the forums a bit more :) (already started a different thread on this before I found yours)
 

Fiersking

Member
hi! for me unfortunately it doesn't work;

i added the library has you said above the good line :

//import com.openfeint.api.ui.Dashboard;
import ${YYAndroidPackageName}.RunnerActivity;
import com.gameanalytics.sdk.*;

but it says the folowing error :



because of this line :
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);

error :
Task :com.XXXXXX.xxxxxx:compileDebugJavaWithJavac FAILED
H:\com.XXXXXX.xxxxxx\src\main\java\com\yoyogames\runner\RunnerJNILib.java:1301: error: cannot find symbol
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
^
symbol: method addErrorEventWithSeverity(GAErrorSeverity,String)
location: class GameAnalytics
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: H:\XXXXXX.xxxxxx\src\main\java\com\KazuMedia\FourPicsAndForWord\GooglePlayServicesExtension.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
 

Speederman

Member
hi! for me unfortunately it doesn't work;

i added the library has you said above the good line :

//import com.openfeint.api.ui.Dashboard;
import ${YYAndroidPackageName}.RunnerActivity;
import com.gameanalytics.sdk.*;

but it says the folowing error :



because of this line :
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);

error :
Task :com.XXXXXX.xxxxxx:compileDebugJavaWithJavac FAILED
H:\com.XXXXXX.xxxxxx\src\main\java\com\yoyogames\runner\RunnerJNILib.java:1301: error: cannot find symbol
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
^
symbol: method addErrorEventWithSeverity(GAErrorSeverity,String)
location: class GameAnalytics
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: H:\XXXXXX.xxxxxx\src\main\java\com\KazuMedia\FourPicsAndForWord\GooglePlayServicesExtension.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
That's only if you want to send the error to GameAnalytics, but you must have the GameAnalytics extension added to your project. If you don't want GameAnalytics, just delete these lines:
GML:
import com.gameanalytics.sdk.*;
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
 

Fiersking

Member
That's only if you want to send the error to GameAnalytics, but you must have the GameAnalytics extension added to your project. If you don't want GameAnalytics, just delete these lines:
GML:
import com.gameanalytics.sdk.*;
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);
i Have Gameanalytics added to my project but i don't know why it doesn't compile when i try your tutorial he bug on this line :
GameAnalytics.addErrorEventWithSeverity(GAErrorSeverity.Critical, sMessage);

mport com.gameanalytics.sdk.*;maybe this path is wrong depend on your project structure ?
 
Last edited:
I tried it as well and it didn't work for me, I would recommend you not to go the 'RunnerJNILib.java' editing way, but instead use the exception_unhandled_handler (maybe something changed somewhere, who knows, but the fact is that editing the file simple doesn't work anymore). Using exception_unhandled_handler gives you basically the same data, only in a slightly more limited way (only those who try to start the app again will send you the report) - but if you have e.g. thousands of players, it doesn't really make a difference anyway.
 
Top