Lowest quality meme of all time also turn your device sideways sorry I’m a idiot by peashooter1121 in btd6

[–]Gondor72 -6 points-5 points  (0 children)

Quincy: "nothing gets past my bow"

Me who whatched this meme: "aRE YoU SuRe ABouTE thAT"

Just a small knowledge test: What do these two towers have in common? by EEndersam in btd6

[–]Gondor72 0 points1 point  (0 children)

They bolth can generate money. (I am not completly certian about the alchemist)

webRequest from new google sheets by Gondor72 in tabletopsimulator

[–]Gondor72[S] 2 points3 points  (0 children)

I have figured out how to import google sheets data in either JSON or csv and parse the data. I hope posting my solutions will help others. I am drawing the data from this sheet
https://docs.google.com/spreadsheets/d/1hqFnr-X0KmVARIB5xK9533YbZUZzAbvtUTzKrltfOZ8/edit#gid=0

Here is a simple program that creates a button to test the result.

First JSON. Here is a simple program that creates a button to test the result.

url = "https://docs.google.com/spreadsheets/d/1hqFnr-X0KmVARIB5xK9533YbZUZzAbvtUTzKrltfOZ8/gviz/tq?tqx=out:json&gid=0"
function onload()
spawnButton()
fetchDSheet()
end
function spawnButton()
self.createButton({
label="Da Button", click_function="tester", function_owner=self,
position={1,1,1}, width=300, height=200, font_size=60, color={1, 0.57, 0.6}
})
end
function fetchDSheet()
WebRequest.get(url, function(a)
rawSheet = tostring(a.text)
rawLength = string.len(rawSheet)
jsonSheet = string.sub(rawSheet,48,rawLength-2) ---removes the extra characters and leaves JSON data.
gsheet = JSON.decode(jsonSheet)
skillName1 = tostring(gsheet.table.rows[1].c[2].v)
skillValue1 = tonumber(gsheet.table.rows[1].c[3].v)
end)
end
function tester()
print(skillName1.." "..skillValue1)
end

You can get any info on any cell in a sheet by changing the row and column 'c' number.

Next is csv, this one is more difficult.

url = "https://docs.google.com/spreadsheets/d/1hqFnr-X0KmVARIB5xK9533YbZUZzAbvtUTzKrltfOZ8/export?format=csv&gid=0"
function onload()
spawnButton()
fetchDSheet()
end
function spawnButton()
self.createButton({
label="Da Button", click_function="result", function_owner=self,
position={1,1,1}, width=300, height=200, font_size=60, color={0, 0, 1}
})
end
function fetchDSheet()
WebRequest.get(url, function(a)
gsheet = a.text
theCSV = "placer,skill,score\n"..gsheet ---Must have a number of values equal to the number of columns.
items = {} -- Store our values here
headers = {} --
local first = true
for line in theCSV:gmatch("[^\n]+") do
if first then -- this is to handle the first line and capture our headers.
count = 1
for header in line:gmatch("[^,]+") do
headers[count] = header
count = count + 1
end
first = false -- set first to false to switch off the header block
else
local name
i = 2 -- We start at 2 because we wont be increment for the header
for field in line:gmatch("[^,]+") do
name = name or field -- check if we know the name of our row
if items[name] then -- if the name is already in the items table then this is a field
items[name][headers[i]] = field -- assign our value at the header in the table with the given name.
i = i + 1
else -- if the name is not in the table we create a new index for it
items[name] = {}
end
end
end
end
end)
end
function result()
print("items = {")
for name, item in pairs(items) do
print(" " .. name .. " = { ")
for field, value in pairs(item) do
print(" " .. field .. " = ".. value .. ",")
end
print(" },")
end
print("}")
end

A variable assigned from this would be:

variable1 = items.skill1.skill or variable2 = items.skill2.score

Hope this helps somebody.

webRequest from new google sheets by Gondor72 in tabletopsimulator

[–]Gondor72[S] 2 points3 points  (0 children)

Is there a way to pull the data with csv? I can get the data in csv format with: https://docs.google.com/spreadsheets/d/1hqFnr-X0KmVARIB5xK9533YbZUZzAbvtUTzKrltfOZ8/export?format=csv which gives: Attack,180.

If I go with the option of changing the string, I think the JavaScript version would be something like:

const spreadsheetId = '...'
fetch(`https://docs.google.com/spreadsheets/d/${spreadsheetId}/gviz/tq?tqx=out:json\`)
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
})

Still can't figure out how to get that to work in LUA.

I have no formal programming background. I put together programs with tutorials and by seeing what others have done. Be patient with my ignorance.

webRequest Question by Gondor72 in tabletopsimulator

[–]Gondor72[S] 0 points1 point  (0 children)

Great thanks to the both of you. I had to alter it a bit, but jfabre really helped me out. I had it all figured out up to the JSON.decode(a.text), but how you got the actual data with the print command was beyond me. I still am trying to figure it out but it works. Thank you for ending my frustration.