Results 1 to 14 of 14

Thread: How to add Auto Updating to Your Script

  1. #1
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default How to add Auto Updating to Your Script

    How to add Auto Updating to Your Script by putonajonny

    This is going to be a very quick nice little tutorial on how to add Auto Updating to your script.

    Step 1.
    Step 1 is to add something to check whether the person is using the most up to date version of your script, if you already have this move on to step 2. The best way is just to have a procedure called "CheckVersion" or something similar and call it at the start of your script. First of all you will need to create a page that stores the most up to date version number of your script. The best site for this I think is pastehtml.com it involves no sign up and allows very quick editing later on.
    When you open the page you will be presented with this:

    Enter the version in the big box, select "Plain Text" and click "Publish Page", on the next page click publish again and then you will be presented with something like:

    Keep a note somewhere of that link, you will need it in a second.
    Now for the coding part, you need to tell your script what version it is so that it can compare the downloaded page with something, so at the top of your script have something like:
    Simba Code:
    Const
    Version = 5;
    Then we need to download the page we made before, for comparison we will save it to a variable first of all. Therefore have something like:
    Simba Code:
    Var
    Ver : String;
    To download the page we are going to use
    Simba Code:
    function GetPage(url : String) : String;
    so therefore you would put:
    Simba Code:
    Ver := GetPage('http://pastehtml.com/view/birjk6g28.txt');
    Remember to have the URL in 's because it is a string.
    You have now stored the most up to date version into "Ver" so if you did:
    Simba Code:
    WriteLn(Ver)
    you should output:
    Code:
    Compiled successfully in 22 ms.
    5
    Successfully executed.
    Now we have our constant and our variable, we will now use if statements to choose what to do next.
    First of all the page may not download properly, so you might want to write something like:
    Simba Code:
    If(Ver = '') then
        begin
          WriteLn('There was an error connecting to the Update Server so I will assume that you have the most up to date Version')
          Exit;
        end;
    That way if the site you are using has server issues the script usage isn't interrupted.
    The next case is if they are using the most up to date version:
    Simba Code:
    If IntToStr(Version) = Ver then
        begin
          WriteLn('You are using the most up to date version -Thank you');
          Exit;
        end;
    This is what happens if they are using the most up to date version, they just carry on using the script.
    What about if you are making the next version of the script, you don't want to have to disable the version checker, so the next case is if the version written in the script is greater than the version stored on the computer:
    Simba Code:
    If Version > StrToInt(Ver) then
            begin
              ClearDebug;
              WriteLn('**You seem to be useing some sort of beta version, be careful')
            end else
            begin
              UpdateScript;
            end;
    This used an "end else" function, which you should know about by now so I won't go into. It then calls the "UpdateScript;" procedure if none of the above were true, so Step 2 is writing that Procedure.


    Step 2.
    This step is where we write what we want the script to do if we have detected that the person is not using the most up to date version. For this I use a new procedure:
    Simba Code:
    Procedure UpdateScript;
    begin

    end;
    First thing we want to do is to check whether the new version of the script is already saved on their computer, and they are just not using it. For this we use the "FileExists" function with something like:
    Simba Code:
    If(FileExists('C:\Simba\Scripts\YourScript v'+Ver+'.simba')) then
        begin
          ClearDebug;
          WriteLn('You are trying to run an older version of this script even though you have the newer version')
          WriteLn('It is stored at "C:\Simba\Scripts\YourScript v'+Ver+'.simba"')
          TerminateScript;
        end;
    This checks whether there is a file with the name YourScript v'+Ver+'.simba (e.g. YourScript v5.simba) stored at C:\Simba\Scripts\. If there is it doesn't need to download the script so it ends and instructs the user where the file is.
    Next I always check that that directory exists, if they have Simba it probably should but just as a fail safe I do:
    Simba Code:
    If(Not DirectoryExists('C:\Simba\Scripts')) then
        CreateDirectory('C:\Simba\Scripts');
    Next we need to download the new script, it therefore needs to be hosted on a website somewhere, see my tutorial in step 1 about http://pastehtml.com. You just need a text file hosted somewhere which you can edit later to add the new version of the script to. For the sake of this tutorial I am going to use http://mysite.com/myscript.txt.
    You will need to temporarily save the script to a Variable so have something like:
    Simba Code:
    Var
    NewScript : String;
    This can be a local variable.
    Then save it to the string using:
    Simba Code:
    NewScript := GetPage('http://mysite.com/myscript.txt')
    We are then going to use 2 functions for creating and writing the file:
    Simba Code:
    function CreateFile(path : string) : longint
    function WriteFileString(FileNum : LongInt; s : String) : Boolean
    I then use them as a part of an If statement:
    Simba Code:
    If ((CreateFile('C:\Simba\Scripts\Merchenting v'+Ver+'.simba') = -1) or (not WriteFileString(0, NewScript))) then
    (CreateFile returns -1 if it fails) It asks for the file number not the file path, since this is the first file we opened it is file 0.
    If this happens I tell it to:
    Simba Code:
    begin
          ClearDebug;
          WriteLn('Sorry I was not able to auto update this script, you can update it manually')
          WriteLn('Opening the web page for you to update')
          OpenWebPage('http://villavu.com/yourthread');
          TerminateScript;
        end;
    You must remember to close the file using
    Simba Code:
    CloseFile(0);
    File number 0 for the reasons I explained above.
    One final check I always do:
    Simba Code:
    If((FileExists('C:\Simba\Scripts\YourScrupt v'+Ver+'.simba')) and Suc) then
        begin
          ClearDebug;
          WriteLn('Updated The Script, new version stored at "C:\Simba\Scripts\Merchenting v'+Ver+'.simba"')
          TerminateScript;
        end
    I shouldn't need to explain what that does.

    If you have any suggestions for this tutorial then let me know, you can see it in action at my Merchenting Script

    -putonajonny


    exampled from my script:
    Simba Code:
    Procedure UpdateScript;
    Var NewScript : String; Suc : Boolean;
    begin
      If(FileExists('C:\Simba\Scripts\Merchenting v'+Ver+'.simba')) then
        begin
          ClearDebug;
          WriteLn('You are trying to run an older version of this script even though you have the newer version')
          WriteLn('It is stored at "C:\Simba\Scripts\Merchenting v'+Ver+'.simba"')
          TerminateScript;
        end;

      If(Not DirectoryExists('C:\Simba\Scripts')) then
        CreateDirectory('C:\Simba\Scripts');
          NewScript := GetPage('http://pastehtml.com/view/bimye4g26.txt')
          If ((CreateFile('C:\Simba\Scripts\Merchenting v'+Ver+'.simba') = -1) or (not WriteFileString(0, NewScript))) then
            Suc := False
          else
            Suc := True;
          WriteLn(FileSize(0));
          CloseFile(0);

      If((FileExists('C:\Simba\Scripts\Merchenting v'+Ver+'.simba')) and Suc) then
        begin
          ClearDebug;
          WriteLn('There is a new version of the script, updating...')
          Wait(500+Random(4000));
          WriteLn('Updated The Script, new version stored at "C:\Simba\Scripts\Merchenting v'+Ver+'.simba"')
          TerminateScript;
        end else
        begin
          ClearDebug;
          WriteLn('Sorry I was not able to auto update this script, you can update it manually')
          WriteLn('Opening the web page for you to update')
          OpenWebPage('http://pastehtml.com/view/biaj2biir.html');
          TerminateScript;
        end;
    end;
    Procedure CheckVersion;
    Begin
      If(WriteLines) then
        WriteLn('Checking if you have the most up to date version');
      Ver := GetPage('http://pastehtml.com/view/biaj1s82r.txt');
      If(Ver = '') then
        begin
          WriteLn('There was an error connecting to the Update Server so I will assume that you have the most up to date Version')
          Exit;
        end;
      If IntToStr(Version) = Ver then
        begin
          If(WriteLines) then
            WriteLn('You are using the most up to date version -Thank you');
        end else
          begin
            If Version > StrToInt(Ver) then
            begin
              ClearDebug;
              WriteLn('**You seem to be useing some sort of beta version, be careful')
            end else
            begin
              UpdateScript;
            end;
          end;
    end;

    Step 3
    When you have updated your script you just need to edit your two hosted pages: to do this using pastehtml just click on:

    Last edited by putonajonny; 12-27-2011 at 11:50 PM.

  2. #2
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Awesome tutorial! I've always done this in my scripts.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  3. #3
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Kyle Undefined View Post
    Awesome tutorial! I've always done this in my scripts.
    What do you think about putting it in "Tutorial for Intermediates" I have no idea of the criteria for each, it isn't a very hard thing to do at all but it isn't the sort of thing that people should/would put on their scripts first of all, that's why I settled on this one.

  4. #4
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Seems like a good place to put it to me.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  5. #5
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Instead of using hard-coded directories, I suggest you use the Setting Constants:
    ScriptPath
    AppPath
    FontPath
    IncludePath
    PluginPath

    It will make it usable by people who install simba somewhere else.

  6. #6
    Join Date
    Feb 2009
    Location
    inside Hello World! Application
    Posts
    232
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Looks awesome maybe it should use same path as where the script is? or in Simba i dunno Function or procedures to do it but its somewhere i think its what mormonman said ^^

  7. #7
    Join Date
    Oct 2006
    Location
    finland, helsinki
    Posts
    2,501
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    If you overwrite the script that is ran in simba, if i remember correctly simba will ask to open the new one. Good tutorial, although i knew all this :P

    Code:
    • Narcle: I recall Jukka releasing a bunch of scripts like this before... Its how he rolls I think. rofl
    • Solarwind: Dude, you are like... t3h s3x.
    • Hy71194: JuKKa you're a machine! You released 3 scripts in 10 minutes! :O
    • benjaa: woah.... Jukka is the man Guildminer pwns all
    • NaumanAkhlaQ: And JuKKa Is my Her0!

  8. #8
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    C:\Simba\ isn't the only path people install Simba too. Also, give the user a choice to upgrade or not. Plus, it's better to just link to the actual script thread (for security concerns, etc).

    Good tutorial though.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  9. #9
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Holy fuck this is sexy!

    Thanks for the tut!
    Oh Hai Dar

  10. #10
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  11. #11
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Nice tutorial.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  12. #12
    Join Date
    Feb 2012
    Location
    Discord
    Posts
    3,114
    Mentioned
    37 Post(s)
    Quoted
    538 Post(s)

    Default

    Ok, I'v been trying to follow this tutorial but I can't seem to grab the version. I'v done this:
    Simba Code:
    program new;
    Var
    Ver: String;

    begin
    Ver := GetPage('https://raw.github.com/SRLTheKiller/Aio-Superheater/master/Version.txt');
    Writeln(ver);
    end.
    to test but I just get a blank line. Why is this happening? the webpage isn't blank and it always loads for me in browser.

  13. #13
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Quote Originally Posted by The Killer View Post
    Ok, I'v been trying to follow this tutorial but I can't seem to grab the version. I'v done this:
    Simba Code:
    program new;
    Var
    Ver: String;

    begin
    Ver := GetPage('https://raw.github.com/SRLTheKiller/Aio-Superheater/master/Version.txt');
    Writeln(ver);
    end.
    to test but I just get a blank line. Why is this happening? the webpage isn't blank and it always loads for me in browser.
    No idea how this stuff even works, but i think if i remember the github site blocks you from coppying in "raw" pages, maybe check what other peopes URL's look like?


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  14. #14
    Join Date
    Feb 2012
    Location
    Discord
    Posts
    3,114
    Mentioned
    37 Post(s)
    Quoted
    538 Post(s)

    Default

    Quote Originally Posted by DannyRS View Post
    No idea how this stuff even works, but i think if i remember the github site blocks you from coppying in "raw" pages, maybe check what other peopes URL's look like?
    o thanks :d, ashaman and superuser both use google code for their scripts so I'll try that

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •