Global Variable not being modified and staying nil

i really need help, idk what to do, this is my code:

function MongoFind(collection, querys, skip, limit)
PerformHttpRequest(url … collection,function(err, text, headers) y = json.decode(text) return end, ‘GET’, json.encode({query = querys}), { [‘Content-Type’] = ‘application/json’ })

return y

end

so, y is a GLOBAL VARIABLE declared as nil at the top of the file. the problem is when i print the value of the function, it still says NIL even tho it should say something like: table: 000001DF3CCB66D0 what am i doing wrong? i am so desperate at the moment :joy:

2 Likes

found out what happened! for future reference, it was because the HTTP request wasn’t fully completed when i called “print(y)” so thanks to @Nick78111 who helped me, i figured out i had to use a callback!

4 Likes