diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 4adbfa7..2ebb9be 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -79,7 +79,6 @@ public static void InsertCoin(InitOptions options = null, Action onLaunchCallBac #endif } - InsertCoinInternal(optionsJson, InvokeInsertCoin, __OnQuitInternalHandler, onDisconnectCallbackHandler); } else diff --git a/Assets/Plugins/PlayroomPlugin.jslib b/Assets/Plugins/PlayroomPlugin.jslib index ec4925b..35fc712 100644 --- a/Assets/Plugins/PlayroomPlugin.jslib +++ b/Assets/Plugins/PlayroomPlugin.jslib @@ -51,7 +51,7 @@ mergeInto(LibraryManager.library, { Playroom.insertCoin(options, OnLaunchCallBack, OnDisconnectCallback) .then(() => { - + Playroom.onPlayerJoin((player) => { var id = player.id; @@ -75,7 +75,6 @@ mergeInto(LibraryManager.library, { }, - /** * @description Checks whether the player is the host of the game. * @returns {boolean} True if the local player is the host, otherwise false. @@ -283,15 +282,30 @@ mergeInto(LibraryManager.library, { console.error( "Playroom library is not loaded. Please make sure to call InsertCoin first." ); - return; } - var returnStr = Playroom.getState(UTF8ToString(key)); - var bufferSize = lengthBytesUTF8(returnStr) + 1; - var buffer = _malloc(bufferSize); - stringToUTF8(returnStr, buffer, bufferSize); - return buffer; + + try { + var returnStr = Playroom.getState(UTF8ToString(key)); + + if (returnStr == null) { + return ""; + } + + if (typeof returnStr !== 'string') { + return ""; + } + + var bufferSize = lengthBytesUTF8(returnStr) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(returnStr, buffer, bufferSize); + return buffer; + } catch (error) { + console.error("JavaScript Library: An error occurred in GetStateStringInternal: \n\n", error); + } }, + + /** * @description Retrieves a dictionary (JSON) value from the game state using the provided key. * @param {string} key - The key to retrieve the dictionary value from the game state.