Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

[WebGL] Base64 string passed from javascript contains invalid characters

$
0
0
Hello! In my WebGL project I want to implement a feature that lets players import/export their savefiles as base64 strings. Since getting proper copy/paste in WebGL is such a pain, I decided to deal with it using javascript's prompt. My JS code OnSaveExportPromptClick: function(arg){ var tSavefile = prompt("Your savefile:", Pointer_stringify(arg)); }, OnSaveImportPromptClick: function(){ var tSavefile = prompt("Paste your savefile:", "test"); if (tSavefile != null && tSavefile != "") { gameInstance.SendMessage('GameManager', 'OnSaveGameImportResult', tSavefile); } } If I just grab the string from Export and paste it into Import, Debug.Log outputs the same string which was exported, but when I try public void OnSaveGameImportResult(string arg){ Debug.Log("Savefile:\n\n" + arg); var plainBytes = System.Convert.FromBase64String(arg); } I get `System.FormatException: Invalid character found.` Any idea how to solve that? EDIT: To clarify, I do the initial Base64 encoding in C# and pass already encoded string to OnSaveExportPromptClick. What I want to do is to be able to copy it from the prompt, paste it in the next prompt and send it back to C#, here is the code: [DllImport("__Internal")] private static extern void OnSaveExportPromptClick(string arg); [DllImport("__Internal")] private static extern string OnSaveImportPromptClick(); public void OnSaveGameExport(){ string rawSave = JsonUtility.ToJson(saveData); var plainBytes = System.Text.Encoding.ASCII.GetBytes(rawSave); // tried UTF8 here, same error string encodedString = System.Convert.ToBase64String(plainBytes); OnSaveExportPromptClick(encodedString); } public void OnSaveGameImport(){ OnSaveImportPromptClick(); } public void OnSaveGameImportResult(string arg){ Debug.Log("Savefile:\n\n" + arg); var plainBytes = System.Convert.FromBase64String(arg); }

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>