[Client Scripting] Creating, Saving and Loading Client Script Settings from Save File [Solved]

Discussion in 'Server and Client Scripting' started by Nightfall Alicorn, Feb 4, 2015.

  1. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    Hi.

    This is something I've wanted to try do for awhile so I wouldn't need to keep editing the script itself. I've learnt how to make a lot of commands to respond to user messages from client scripting but I'm kinda stuck.

    Basically I wanna make a function to:
    - create a default settings file, if one doesn't exist to load from
    - be able to save changes to a settings file
    - be able to load from settings file

    I've had a look at Crystal Moogle's Client Script on how she made hers but I'm confused with how she's written it. From what I understand so far, there's an init check for when the user logs on, to prevent crashes I think, then it goes to loadSettings or loadFromRegistry. I think these are the four important functions:
    loadSettings: function loadSettings(json, defaultUsed, silent) {
    loadDefaultSettings: function loadDefaultSettings() {
    loadFromRegistry: function loadFromRegistry() {
    saveSettings: function saveSettings() {

    So far, I see how the saveSettings gets all the variables and stores them all in an object which is then converted into a single line json string, in a memory.json file.

    I've found cleanFile('memory.json'); under loadSettings but there no info on exactly what it does to clean the file in this topic http://pokemon-online.eu/threads/client-scripts.14355/.

    I appreciate if anyone could provide a template of an example, commented code will help a lot.

    Thanks.

    Edit: Success. I've made a template with some commented code to help those that are interested. My template is found here: http://pastebin.com/dS6ipqXR Please note it's just an example script.
     
    Last edited: Feb 7, 2015
  2. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    cleanFile is a function from within my scripts.
    Code (JAVASCRIPT):
    1.  
    2. function cleanFile(filename) {
    3.     sys.appendToFile(filename, "");
    4. }
    5.  
    It essentially adds "nothing" to a file. All it does is create the file if it doesn't exist.
     
  3. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    Thank Crystal. I forgot to check if it was a built-in function or script written function.
     
  4. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    I've got most of the script working now but the only problem I'm having is testing if the settings file exists or not. I've tried placing it in a try catch section but I still get a warning message like this for example:

    Script Warning in sys.getFileContent(filename): Error when opening Client Script Settings.json: No such file or directory


    I think this is the code for testing but I might be wrong.
    Code (JavaScript):
    1. if (sys.getFileContent(vgMemoryFileName) == "") {
    2.     print(vgBotName + "No settings file found.");
    3.     }
    Be great if someone could help with this last part.

    Edit: Never mind, the solution was right there. Sorry, guess it was a bit late and I was sleepy.
     
    Last edited: Feb 6, 2015