Jump to content

Help with using the env.log command to stop blowing up the script


Go to solution Solved by Grimes,

Recommended Posts

Posted

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
Posted
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. 

  • Like 2

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted
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. 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...