GMS 2 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.
 
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

Member
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".
 
Top