GMS 2 error handling and capture

Discussion in 'Programming' started by Daniel Mallett, Feb 16, 2019.

Tags:
  1. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    151
    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.
     
  2. marasovec

    marasovec Member

    Joined:
    Sep 15, 2016
    Posts:
    325
    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: Feb 16, 2019
  3. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    151
    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.
     
  4. CombatCalamity

    CombatCalamity Member

    Joined:
    Feb 16, 2019
    Posts:
    67
    There is a way, you just need to do them yourself. This is how all other softwares out there do it.

    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.
     
    marasovec likes this.
  5. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,405
    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.
     
    The Reverend likes this.
  6. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    415
    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.
     
  7. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    151
    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
     
  8. Speederman

    Speederman Member

    Joined:
    Jun 23, 2016
    Posts:
    46
    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 'package com.yoyogames.runner':
    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: Aug 9, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice