Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How is the if statement getting the nil value from the first part in parenthesis? (SOLVED)

Asked by 7 years ago
Edited 7 years ago

Hey guys, As you can probably tell from the title, this following code keeps telling me I'm comparing a nil value to a number.

Here is the code:

local hs = game:GetService("HttpService")
local got_table = hs:GetAsync("https://search.rprxy.xyz/catalog/json?CatalogContext=1&Subcategory=2&SortAggregation=5&PageNumber=1&LegendExpanded=true&Category=2", true)
local json_table = hs:JSONDecode(got_table)
local dic_values = 0;
local common = {} -- 0 and 2,500
local uncommon = {} -- 2500 and 9,000
local rare = {} -- 9000 and 75,000
local legendary = {} -- 75000 and 500,000
local ultra_rare = {} -- 500,000 and 999,999,999,999


for i = 1, 44 do
    print("Page #"..i..":")
    repeat

    for index,value in next, json_table do -- Counts the amount of values in the dictionary.
        dic_values = dic_values + 1;
    end

    got_table = hs:GetAsync("https://search.rprxy.xyz/catalog/json?CatalogContext=1&Subcategory=2&SortAggregation=5&PageNumber=" .. i .. "&LegendExpanded=true&Category=2", true)
    json_table = hs:JSONDecode(got_table)
    until dic_values > 0

    for index, value in next, json_table do -- Prints all the values inside dictionary.
        if ((tonumber(value.BestPrice) or tonumber(value.Price)) >= 0 and (tonumber(value.BestPrice) or tonumber(value.Price)) <= 2500) then
        print(tonumber(value.BestPrice))
    end
    end
end

print("Values are done!")

Apparently, the first part of the if statement on line #25, which is:

if ((tonumber(value.BestPrice) or tonumber(value.Price))

is giving me a nil value. I have no clue as to how that is happening because, I am using ternary and an object in catalog can't be missing both a BestPrice and a Price. So, if the first value is nil, it should just go to the next value.

Any help is appreciated and thank you, once again.

~~ KingLoneCat

0
Could you possible print the JSON table itself as a string? I'd like to see what it has in it. Shawnyg 4330 — 7y
0
But, I figured it out. Apparently, for some reason in the string, the creator of the item added a comma in the number so, I had to remove that with gsub but, thanks for the attempt to help me. KingLoneCat 2642 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

here it looks like you have an extra parenthesis. I'm not sure though so do not downvote this,

(tonumber(value.BestPrice) or tonumber(value.Price)) <= 2500) 
0
He only copied one line from a multi-line boolean condition. If there were a syntax mistake, a corresponding error would have been produced. duckwit 1404 — 7y
Ad

Answer this question