I'm trying to create a function that checks the value of a playerstat and compares it to a given value.
For example if a player tries to buy something it should check if the playerstat (money) is more than or equal to the given value (the price of an item).
However there are other situations where I have to check if the playerstat is either greater than or lesser than the given value.
I'm having trouble figuring out how to tell the script what math comparison to do. I tried storing math operators such as > and == in a table or variable but found out you can't store those.
For example I can't do (as a watered down version)
equalTo = == lessThan = < function blah(operator, arg1, arg2) if arg1 operator arg2 then print(true) end end blah(equalTo, 5, 5)
I have done a lot of searching but feel like I don't know the correct lua terms to find what I'm looking for if it is out there. Any help appreciated, thanks!
edit: I made it work with the biggest hackjob of if statements for testing sake but surely there's a better way
local operators = {"==", ">", "<", ">=", "<="} function PlayerModule.CheckData(player, dataName, value, numerator) data = playerData[player] for i, dataValue in pairs(data) do if i == dataName then for x, y in pairs(operators) do if y == numerator then if x == 1 then if dataValue == value then return true end elseif x == 2 then if dataValue > value then return true end elseif x == 3 then if dataValue < value then return true end elseif x == 4 then if dataValue >= value then return true end elseif x == 5 then if dataValue <= value then return true end end end end end end end