Skip to content

Instantly share code, notes, and snippets.

@andybak
Created October 6, 2023 09:39
Show Gist options
  • Save andybak/f29593152ca24bfc3585d9845a502c02 to your computer and use it in GitHub Desktop.
Save andybak/f29593152ca24bfc3585d9845a502c02 to your computer and use it in GitHub Desktop.
local lume = require("lume")
Settings = {
description="Calls an API to choose a random Kenney model from poly.pizza",
previewType="quad"
}
function Start()
headers = {}
headers["x-auth-token"] = "---------"
requestNewModel()
end
function Main()
if Brush.triggerReleasedThisFrame then
requestNewModel()
if modelUrl ~= nil then
model = Model:Import(modelUrl)
end
end
end
function requestNewList(id)
url = "https://api.poly.pizza/v1/user/Kenney"
WebRequest:Get(url, onGetList)
end
function onGetList(result)
resultJson = json.parse(result)
randomItem = lume.randomchoice(resultJson.models)
requestNewModel(randomItem.ID)
end
function requestNewModel(id)
url = "https://api.poly.pizza/v1/model/" .. id
WebRequest:Get(url, onGetModel)
end
function onGetModel(result)
resultJson = json.parse(result)
modelUrl = resultJson.Download
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment