I need to check if my table canCall is empty.
What I am trying to do is:
but it seems like it does not work like that. Because everytime I get table canCall is empty, even if it is not.Code:if #canCall > 0 then print("table canCall contains something") else print("table canCall is empty") end
[DOUBLEPOST=1431168137][/DOUBLEPOST]Or should I just do
Code:if canCall == {} then
Solved Check if table is empty etc
Discussion in 'Rust Development' started by LaserHydra, May 9, 2015.
-
The #tablevar is something you can only use if the table is using the default keys (1, 2, 3, ...) so as soon as you define your own keys tablevar['name'] = 'Mughisi', tablevar['userid'] = 99999, .... you won't be able to use the # in front of the table anymore, another thing you could do is just simply add a count function to your plugin that returns the amount of values in any given table, unregarding the type of the key, so you'd simply do something like
Code:local tablevar = {} if self:Count(tablevar) == 0 then print("Empty table") else print("Table contains values!") end
Code:function PLUGIN:Count( tbl ) local count = 0 for _ in pairs( tbl ) do count = count + 1 end return count end
-
Code:if canCall == {} then
-
-
[DOUBLEPOST=1431169495][/DOUBLEPOST]@Mughisi Wow Idk what the hell I am doing wrong. I think I just built it up too complicated... I kinda lost the overview...
I've build up that you can buy a token and you can check if you have a token. So but if you buy a token and throw a grenade, it works. But if you buy a token and then look if you got a token it says I got none, and If I throw a grenade then, it also doesnt work. It seems like my checking function anyhow resets the table or something like that... I can't find the issue, you propably find it in a second ^^ :c
Could you do me the favor and take a quick look at it?Last edited by a moderator: May 9, 2015 -
Code:local tabletest = {} if tabletest == {} then print("Table is empty") end
-
-