• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

LocalStorage (html5)

olive

Member
3rd Party Module Dev
Tutorial Author
Patreon Bronze
Joined
Jul 17, 2017
Messages
76
I've put together a (very) small module that gives access to saving and loading from LocalStorage on the html5 target. It's similar to the existing SaveState, but you can specify your own key/value pairs instead of needing to have it be one long string. It's about as close as you can get to being able to save things to disk for html5.

Repo with example: https://github.com/wickworks/localstorage

localstorage.cxs
Code:
#If TARGET="html5"
    Import "native/localstorage.js"
#Else
    #Error "The localstorage module is only available on the html5 target"
#Endif

Extern

Function SaveLocalStorage(key:String, value:String)
Function LoadLocalStorage(key:String)

native/localstorage.js
Code:
SaveLocalStorage = function(key, value) {
    localStorage.setItem(key, value);    //key can't start with dot in Chrome!
    return 1;
}

LoadLocalStorage = function(key) {
    var state = localStorage.getItem(key);
    if (state) return state;
    return "";
}

(This is the first time I've managed to get Extern working to run javascript code! It wasn't as hard as I was afraid it would be.)
 
Thanks. You can also do this. This will make you a download file.
Chrome will block this of course you have to accept that files are allowed to save to your device.

Save file on HTML5 platform :

savefile.cxs
Code:
' A simple way to save/download a string on HTML5 target

Import mojo2

Import "commands.js"
Extern
Function SaveString(content:String)
Public

Function Main()
    New MyApp
End

Global canvas:Canvas

Class MyApp Extends App

    Method OnCreate()
        canvas=New Canvas
        SetUpdateRate 0
        SaveString "It works!"
    End Method
   
    Method OnUpdate()
        If MouseHit(0) Then SaveString "It works!"
    End Method
   
    Method OnRender()
        canvas.Clear
        canvas.Flush
    End
   
End Class

commands.js
Code:
function SaveString(content){
    uriContent = "data:application/octet-stream," + encodeURIComponent(content);
    window.open(uriContent,"Download File");
}
 
Neat! I didn't know that was an option. Do you have a corresponding solution for being able to let users upload files to the browser & access that data in cerberus?

LocalStorage is nice because you can save/load without user input (I'm now using it for game options, where I don't necessarily want to bother folks by forcing them to manually download/upload a preferences file).
 
Neat! I didn't know that was an option. Do you have a corresponding solution for being able to let users upload files to the browser & access that data in cerberus?

LocalStorage is nice because you can save/load without user input (I'm now using it for game options, where I don't necessarily want to bother folks by forcing them to manually download/upload a preferences file).

I do, I think I should give myself some time and dig it up at some point. It would be handy to have.
I'll give you a message as soon as I have it ready.
 
Back
Top Bottom