I need help with URLs.

  • LittleProgramming
    24th Feb 2021 Member 0 Permalink

    Hello. I am busy at work making a Lua mod for TPT. (No, not that sad excuse for a mod that was Little's Pack)

    I have tried to incorporate an autoupdater using the code in autorun.lua to get a test PNG i uploaded and download it to TPT, however that didn't do much, it just gave me some weird text document that said it moved permanently - and the link in the document didnt do anything in TPT.

    So, as a last resort, I wanna make a discord server. I don't, however, know how to open up URLs in a browser in TPT as some dude has deleted the Platform page for the Lua API.

  • jacob1
    24th Feb 2021 Developer 1 Permalink
    For getting things from the internet, you should definitely use http.get(). It will handle the redirection for you. Do be careful that you have a stable url to download from, so that the script doesn't overwrite itself with junk.

    Making unofficial discord servers is against the rules, you should find a different way to share updates for your script.

    The platform page wasn't deleted, it never existed in the first place. Here is a link to the C++ code for the platform api, it's pretty easy to figure out how these functions work: https://github.com/The-Powder-Toy/The-Powder-Toy/blob/master/src/lua/LuaScriptInterface.cpp#L3601
    So for example, you want platform.openLink
  • LittleProgramming
    24th Feb 2021 Member 0 Permalink

    @jacob1 (View Post)

     Good thing you told me about the discord thing. That came in clutch.

    As for the http:get(), how does it work with Google Drive?

    Another thing:
    What does "string expected, got userdata" mean?

    Here's my code

    local re = http.get("https://drive.google.com/file/d/(file link here, just censored)/preview")
    f=io.open("test.txt","w")
    f:write(re)
    f:close()

    Edited once by LittleProgramming. Last: 24th Feb 2021
  • jacob1
    24th Feb 2021 Developer 0 Permalink
    @LittleProgramming (View Post)
    http.get returns an HTTPRequest object, not the final result. You have to call :finish() on the request to get the string data for the actual result. The wiki has more info on this.

    Also, google drive doesn't provide a stable link you could use for hosting updates. So you would have issues hosting a script update server there.
    Edited 2 times by jacob1. Last: 24th Feb 2021
  • LittleProgramming
    24th Feb 2021 Member 0 Permalink

    @jacob1 (View Post)

     Thank you for this advice.

    Do you recommend any other cloud services that would work well?

    P.S: I don't wanna use paid cloud services because the net income of a free mod would be negative, I wanna use something free. I would use my hard drive but that has multiple problems:

     

    1. You can only update or even check for one if I am online

    2. My IP address is leaked in the source code

    3. My PC only has one hard drive (which won't last forever!), so if that went down the whole update mechanism would collapse

    4. I could use my SSD but that'd be really hard to code if possible

    5. I use linux anyway, I don't know how it'd react with exploring the EXT4 system of another computer

    6. My computer isn't a server; it's not open to filesharing anyway

    Edited once by LittleProgramming. Last: 24th Feb 2021
  • jacob1
    24th Feb 2021 Developer 0 Permalink
    @LittleProgramming (View Post)
    You could try using a site like pastebin.com to host it. There are probably other paste services out there too.

    Hosting it off your computer would definitely be a bad idea, and complex to set up. So don't do that :P
  • LittleProgramming
    24th Feb 2021 Member 0 Permalink

    @jacob1 (View Post)

     Holy crap thanks

    Edit: I have decided that I want to use GitHub.

    Edited once by LittleProgramming. Last: 24th Feb 2021