TEMPEST.114 Posted February 17, 2024 Posted February 17, 2024 So I'm using the scripting engine env.log to write out data to my own little logging system. However I've never worked out how to make it handle anything I throw at it, or when it gets something I wasn't expecting, e.g. I think I'm going to get a string and its nil instead, or I think I'm getting a string and it gets a table. Does anyone have any code that can handle these kind of curveballs nicely?
Solution Grimes Posted February 17, 2024 Solution Posted February 17, 2024 if var then if type(var) == "string" then -- do string things elseif type(var) == "table" then -- do table things end else -- its nil end Check for its existence and the type. 2 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
TEMPEST.114 Posted February 17, 2024 Author Posted February 17, 2024 13 hours ago, Grimes said: if var then if type(var) == "string" then -- do string things elseif type(var) == "table" then -- do table things end else -- its nil end Check for its existence and the type. Thanks Grimes. Never seen the 'type()' command before. Should have guessed but thanks for that.
Recommended Posts