Hello.
Is there any way to get infos about save like the name, description, creator nickname, votes amount etc into an array or variable?
I want to challange myself making a save related script that needs to get these infos.
TPT mods like Cracker1000 or Jacob1's mod can show ratings amount on saves, as for name, descriptions and the rest i doubt it, but i'm not a coder so take the opinion with a grain of salt
TLDR: you can try to replicate the vote showing system from the 2 mods i mentioned and try to do the thing with them, but otherwise idk
You can look into the http part of the lua api
I recommend using the .json endpoints like https://powdertoy.co.uk/Browse/View.json?ID=2198
You can use smth like this to parse the json and get all the info like that
Thanks for feedback guys.
Appreciate yalls help
...i have got an unexpected problem.
every time i try to get anything with http.get gives me userdata and i cant use it in any way.
any idea how do i fix that ?
edit: i probably didnt understand the article on tpt wiki.
Using a code like yours for some reason gave me nothing.
example code snippet (remade from scratch bc deleted in orig script so forgive weird names) :
json = request("scripts/json")
function getusername(saveid)
request = http.get("https://powdertoy.co.uk/Browse/View.json?ID="..saveid)
if request == "done" then
rawjson = request:finish()
savetable = json.decode(rawjson)
print(savestable["Username"])
end
end
Expected output is the creator's name, but i always get "" printed.
And after writing print(savestable["username"]) i always get nil (didnt use locals so i could "debug" this way)
Meanwhile, if i use these commands in console one after another it works perfectly:
saveid = *number*
request = http.get("https://powdertoy.co.uk/Browse/View.json?ID="..saveid)
rawjson = request:finish
savestable = json.decode(rawjson)
print(savestable["Username"])
I have got no idea what to do lol
You have to wait for the http request to finish somehow. The easiest way would be to use a coroutine (this creates a new execution thread and waits for the thread to finish, the thread itself waits as long as the request is running).
Something like this:
json = request('scripts/json') http_waiter = coroutine.create(function(http_request) while true do while http_request:status() == 'running' do end -- Busy waiting, not ideal http_request = coroutine.yield(http_request) end end) function get_save_json(id) local _, http_request = coroutine.resume(http_waiter, http.get("https://powdertoy.co.uk/Browse/View.json?ID=" .. id)) if http_request:status() == 'dead' then error('http request died') end local http_body, http_response_code = http_request:finish() if http_response_code >= 400 then error('http error ' .. http_response_code) end return json.decode(http_body) end
if request == "done" thento
if request:status() == "done" then. Your other function calls look fine, you just need to split it into starting the request and checking it later every frame.