Created
October 6, 2023 09:39
-
-
Save andybak/f29593152ca24bfc3585d9845a502c02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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