Semtex Auto Updater Tutorial
Last Updated: September 25th, 2015
Introduction
Hello, welcome to my very first tutorial. I decided to make this tutorial because the tutorials available regarding Auto Updater are somewhat outdated. I myself spent quite some time figuring out how it worked. Therefor I wanted to make this guide, so you would avoid spending the amount of time that I did. This tutorial will guide you step by step how to add Auto Updater to your script and how to manage your script.
For this tutorial, we will be using GitHub. Our very own @
The Mayor; provided the code we will be using in the actual script.
Table of Contents
- Step 1: Registering at GitHub
- Step 2: Creating your repository
- Step 3: Downloading and setting up GitHub Desktop
- Step 4: The script and the code
- Step 5: Maintaining Script updates
Step 1: Registering at GitHub
The first thing you need to do is go to
https://github.com/ and register.
On the front page in the right side, you will see three boxes labeled, Pick a username, your email and create a Password.
It looks as follows:
Fill out the boxes. (Example for username could be SRL (Account name), like mine “SRLTest”)
After you have filled out all three boxes, click “Sign up for GitHub”.
The next page is where you choose a plan. Just click the green button Finish sign up at the bottom.
You have now registered and before continuing, I recommend verifying your email address. Log unto your email and should have gotten two emails from GitHub. A welcome mail and the mail where you verify your email address. Open then one with verify email.
You should now see something like this:
Click the button “Verify email Address”. We are now ready to continue.
Step 2: Creating your repository
When you log into GitHub it should look something like the picture below:
Click the green button “New repository”
You can now see the following page:
Repository name, can be anything. For this example, we will name it “SRLScripts”. We will make folders for the script we are adding auto updater to later on.
In the description box, you can fill out anything you want or nothing at all. I decided to leave it blank in this example, but you could write “All my SRL Scripts”.
Leave it on public. If you choose private (only paying users can choose this option), no one would be able to see the content added to the repository.
Now check the box “Initialize this repository with a README”. We will not be using it, but it is easier if we add it when we create the repository.
When you have filled out all the information, click the green button “Create repository”. We have now created the repository.
You should now see the following page:
In case you were wondering, a repository is a directory of files (In this case).
Onward to the next step.
Step 3: Downloading and setting up GitHub Desktop
Click the following link
https://desktop.github.com/
Click the big blue button “Download GitHub Desktop” it should look like the following:
Double click the file when it is finished downloading and click Install. It will now download the required files for the installation (this could take some time depending on how high your bandwidth is).
GitHub runs by itself when the installation is finished.
You should now see the following:
Enter the username you chose earlier and the password you chose, and then click Log in.
Just click Continue on the next page and finally click “dashboard” in the line: Head over to your dashboard to get started!”
Now click the plus in the left top side and choose “Clone”. Click then one showing, it will have the name of the repository that we created earlier on, in this example it is SRLScripts. It should look like the following:
Click the button at the bottom “Clone SRLScripts (or whatever you named it)”. You will have to choose a directory. I use the default one, but you choose whatever. Wait for it to finish.
Right click “SRLScripts (or whatever you named it) in the top left corner and choose open in explorer.
Delete the README file and add a new folder. Name it after your script. I will name mine SemtexFishingGuild.
Now make a new text file document within the newly created folder, name it “Version”.
Open up the text document file and input version number of your script. In my case, it is 1.2
It should look like this:
Save the file and close it.
Now move your script within the folder, like this:
We are now ready to continue to the next step.
Step 4: The script and the code
The first thing you need to do is add a constant to your script.
Like so:
Simba Code:
program SemtexFishingGuild;
{$DEFINE SMART}
{$i srl-6/srl.simba}
{$i sps/lib/sps-rs3.simba}
{$i srl-6/lib/misc/srlplayerform.simba}
const
Version = 1.2;
The procedure for auto updating is like this:
Simba Code:
procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/version.txt'));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);
if newVer > Version then
begin
printf('Updating (Script Name Here).simba from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + '(Script Name Here).simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/(Script Name Here).simba'));
closeFile(newFile);
print('Please reopen this file');
terminateScript();
end;
end;
Fill in the (Name) in the throughout the code, with your own information. In my case the code would be like this:
Another way of getting the URL that needs to be used is to, is by logging into the GitHub Webpage, enter "SRLScripts" under "Your Repositories".
Then click the script folder, in my case it's SemtexFishingGuild.
You should see 2-3 files here, Version.txt and scriptname.simba and the updater.
Click on "scriptname.simba"
Now click the button "Raw" and copy the URL from the page you are taken to.
It is very important that you add the http:/ /tomstewart.net/proxy.php?url= in front of the URL.
So the URL isn't just: https:/ /raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba
but: http:/ /tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba
If you don't add http:/ /tomstewart.net/proxy.php?url= then the script won't be able to get the data it needs.
Simba Code:
procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/version.txt'));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);
if newVer > Version then
begin
printf('Updating (Script Name Here).simba from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + 'SemtexFishingGuild.simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild.simba'));
closeFile(newFile);
print('Please reopen this file');
terminateScript();
end;
end;
The next thing you need to do is call the procedure in your Setup loop.
I call it here, at the begging of the Setup Loop and before all the playerform procedure etc.:
Simba Code:
clearDebug();
getUpdate();
getMap();
initPlayerForm();
runPlayerForm();
Save the program and exit it.
Now for the file you attach to your thread on Villavu.
Start a new simba program.
Put in the following code:
Simba Code:
program (Script Name Here)Updater;
{$i srl-6/srl.simba}
(* Auto-Updater file:
Run to get latest version of the script.
The script will appear in the same directory as this script.
*)
const
Version = 0.0;
procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/version.txt '));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);
if newVer > Version then
begin
printf('Updating ' + 'SemtexFishingGuild.simba' + ' from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + '(Script Name Here).simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/(Script Name Here).simba'));
closeFile(newFile);
print('New script saved to: ' + scriptPath);
terminateScript();
end;
end;
begin
clearDebug();
disableSRLLog := True;
getUpdate();
end.
Fill in the (Name) in the throughout the code, with your own information. In my case the code would be like this:
Simba Code:
program SemtexFishingGuildUpdater;
{$i srl-6/srl.simba}
(* Auto-Updater file:
Run to get latest version of the script.
The script will appear in the same directory as this script.
*)
const
Version = 0.0;
procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/ SRLTest/SRLScripts/master/SemtexFishingGuild/version.txt '));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);
if newVer > Version then
begin
printf('Updating ' + 'SemtexFishingGuild.simba' + ' from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + 'SemtexFishingGuild.simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/ SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba '));
closeFile(newFile);
print('New script saved to: ' + scriptPath);
terminateScript();
end;
end;
begin
clearDebug();
disableSRLLog := True;
getUpdate();
end.
Save the program within the Repository Directory, you chose in Step 3, where we created the Version text document and you put the script.
Now you have created the means to auto update your script. HOWEVER GitHub have not yet received any of files you put in your script folder. We need to synchronize GitHub Desktop with the GitHub Website.
Open up GitHub Desktop and go into you repository. Right under where it says Sync, click the larger ring there is and you will now see the following (with your information of course):
Fill out Summary and optionally Description.
You write what changes you made since the last time you synchronized your script. In this case, it is the initial release.
Click “Commit to Master” followed by clicking on “Sync”
You can now attach the AutoUpdater file we created to your thread and you will never have to change again.
Step 5: Maintaining Script updates
The hard part is over and the rest is quite easy.
When you need to update a script, all you have to do is change the version number in your Version.txt file, and make sure you change the program.simba file with all the changes you made.
Remember to change the const version to the version number you wrote in the version.txt file.
If I wanted to update my script, I would change the version.txt file to 1.3 and change the const within the script to 1.3.
When you have made the desired changes, you will have to commit the changes and synchronize them just as you did in the last part of Step 4.
Now you should know everything about adding auto updater to your script and maintaining new updates.
Please feel free to ask questions if you are having trouble or just curious.
If you have any suggestions to this guide, please share them as well
I hope you like this guide and I wish you the best of luck with adding auto updater to all of your scripts!