Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: GetStateString. #42

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static void InsertCoin(InitOptions options = null, Action onLaunchCallBac
#endif
}


InsertCoinInternal(optionsJson, InvokeInsertCoin, __OnQuitInternalHandler, onDisconnectCallbackHandler);
}
else
Expand Down
30 changes: 22 additions & 8 deletions Assets/Plugins/PlayroomPlugin.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mergeInto(LibraryManager.library, {

Playroom.insertCoin(options, OnLaunchCallBack, OnDisconnectCallback)
.then(() => {


Playroom.onPlayerJoin((player) => {
var id = player.id;
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading