|
Post by paladiex on Aug 9, 2017 22:27:47 GMT
I am trying to compare a "version.lua" file in the user's current directory to one online. I already know latestVersion = httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua") will create a variable with the version number posted on that link. I need a currentVersion = ? to reference the "version.lua" file in (localPath .. "version.lua")
|
|
|
Post by Mercobots on Aug 9, 2017 22:38:18 GMT
hello
i use this, this is what are you loking for ?
version.lua
return "x.x.x"
main.lua
local current_version = dofile("version.lua")
local http_version = httpGet("https://host/version.lua")
if current_version < http_version then return true end
|
|
|
Post by paladiex on Aug 9, 2017 22:42:42 GMT
hello i use this, this is what are you loking for ? version.luareturn "x.x.x" main.lualocal current_version = dofile("version.lua")
local http_version = httpGet("https://host/version.lua")
if current_version < http_version then return true end Why do you use "local"
|
|
|
Post by Mercobots on Aug 9, 2017 22:48:29 GMT
When using local the variable will only be accessible in this file ... i usually use local to not mix or override global vars with the same name
|
|
|
Post by paladiex on Aug 9, 2017 22:53:01 GMT
When using local the variable will only be accessible in this file ... i usually use local to not mix or override global vars with the same name I changed to "latestVersion = httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua") currentVersion = dofile(localPath .."version.lua") print (latestVersion) print (currentVersion)" and version.lua is set as return "x.x.x". With this the bot is printing "return "0.0.2" 0.0.2" User Abort! Any way to make the same version.lua file display "0.0.2" on both? Edit 1: What I mean is that your method sets the variable "latestVersion" to "return "x.x.x"" when I need it to perform that action. I suppose I could do 2 version files, a local one and one placed online just for reference. This seems clunky though. Is this really what you use?
|
|
|
Post by Mercobots on Aug 9, 2017 23:14:19 GMT
to do so, you need to use loadstring with httpGet, this will put all version.lua content in a function
local http_version = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))() if current_version < http_version then return true end
--or
local http_version = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))
if current_version < http_version() then return true end
|
|
|
Post by paladiex on Aug 9, 2017 23:24:09 GMT
to do so, you need to use loadstring with httpGet, this will put all version.lua content in a function local http_version = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))() if current_version < http_version then return true end
--or
local http_version = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))
if current_version < http_version() then return true end
latestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua")) currentVersion = dofile(localPath .."version.lua") print (latestVersion) print (currentVersion) if current_version == latestVersion then print ("You are up to date!") else print ("You need to update!") end This displays function 0.0.2 You need to update! user Abort!
|
|
|
Post by Mercobots on Aug 9, 2017 23:39:09 GMT
you had some erros at your code
latestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))()
if current_version == latestVersion then print ("You are up to date!") else print ("You need to update!") end
latestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))()
currentVersion = dofile(scriptPath() .. "version.lua")
print(latestVersion)
print(currentVersion)
print("if result = ", currentVersion == latestVersion) print("------------------------------")
if currentVersion == latestVersion then print("You are up to date!") else print("You need to update!") end
|
|
|
Post by paladiex on Aug 9, 2017 23:40:47 GMT
you had some erros at your code latestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))()
if current_version == latestVersion then print ("You are up to date!") else print ("You need to update!") endlatestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))()
currentVersion = dofile(scriptPath() .. "version.lua")
print(latestVersion)
print(currentVersion)
print("if result = ", currentVersion == latestVersion) print("------------------------------")
if currentVersion == latestVersion then print("You are up to date!") else print("You need to update!") end After tinkering I've gotten it to display 0.0.2 for both I used getVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua")) latestVersion = getVersion() currentVersion = dofile(localPath .."version.lua") print (latestVersion) print (currentVersion) if currentversion == latestVersion then print ("You are up to date!") else print ("You need to update!") end Unfortunately it is not displaying "You need to update!" which means that my 2 variables are not being seen as equal. That or I am misusing my bottom line. I do not believe I can use > or < since these are being treated as character values rather than numerical values. Edit 1: i typed "currentversion" instead of "currentVersion". Once I fixed that the script is working as intended. Thanks!!!
|
|
|
Post by Mercobots on Aug 9, 2017 23:48:39 GMT
|
|
|
Post by paladiex on Aug 10, 2017 0:02:10 GMT
I am using this now getNewestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua")) latestVersion = getNewestVersion() currentVersion = dofile(localPath .."version.lua") print (currentVersion) print (latestVersion) if currentVersion == latestVersion then toast ("You are up to date!") else httpDownload("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua", localPath .."version.lua") httpDownload("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/PalPowerUp.lua", localPath .."PalPowerUp.lua") scriptExit("You really have Updated PalPowerUp bot!") end Unfortunately it appears that ankulua is not going to the github every time to get a new url. It only refreshes that url page when I stop the ankulua service. This is quite annoying.
|
|
|
Post by Mercobots on Aug 10, 2017 0:13:14 GMT
i have to say is working fine here , What are you trying to say with "refreshes" ?
|
|
|
Post by paladiex on Aug 10, 2017 0:26:11 GMT
i have to say is working fine here , What are you trying to say with "refreshes" ? I've got version.lua on github with the version 0.0.4, I start ankulua and it notices that the local file is 0.0.3, the script updates then stops (The play button is still visible). I hit play, it notices a match now. I immediately updated the github to 0.0.5, I click stop, then I click play. It believes the newest version is still 0.0.4, the only explanation is that it is using the old (cached) website version of version.lua; to confirm if I go into ankulua and stop the service then start the service and hit play then it recognizes that the webpage has updated.
|
|
|
Post by Mercobots on Aug 10, 2017 0:36:26 GMT
i'm not sure, but i think the delay comes from github when updates the "raw" page!
try run some tests like this one
-- load ankulua comminLib commonLib = loadstring(httpGet("https://raw.githubusercontent.com/AnkuLua/commonLib/master/commonLib.lua"))()
simpleDialog("", "\n\t Load new file at github and start test")
for i = 1, 4 do local _wait = 5 * i getNewestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))() print(getNewestVersion,"\t ".._wait.." seconds") toast("new test in " .. tostring(_wait)) if i == 4 then break end wait(_wait) end
|
|
|
Post by paladiex on Aug 10, 2017 0:48:22 GMT
i'm not sure, but i think the delay comes from github when updates the "raw" page! try run some tests like this one -- load ankulua comminLib commonLib = loadstring(httpGet("https://raw.githubusercontent.com/AnkuLua/commonLib/master/commonLib.lua"))()
simpleDialog("", "\n\t Load new file at github and start test")
for i = 1, 4 do local _wait = 5 * i getNewestVersion = loadstring(httpGet("https://raw.githubusercontent.com/Paladiex/PalPowerUp/master/version.lua"))() print(getNewestVersion,"\t ".._wait.." seconds") toast("new test in " .. tostring(_wait)) if i == 4 then break end wait(_wait) end
This script essentially just waits if the version numbers match until a change is recorded, correct? I pushed the update, refreshed the github page on my laptop (pushed update on my desktop), saw the change, then ran the bot. I waited 5 min, ran the bot again, still falsely identifying the version. So this time I pushed a version, refreshed the page, saw the change, stopped ankulua service, started ankulua service, viola it registered the new version in under 1 min. If it was on github's end it wouldn't matter what device I am on, it would display the old version on all of them.
|
|