simple trick - making a table /reload proof

Discussion in 'Programming & Scripting' started by zbizu, May 31, 2016.

  1. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,438
    Likes Received:
    1,329
    Best Answers:
    0
    Some complex systems get ruined when you do /reload (if you have addEvent, it may refer to an empty table)

    You can avoid redefining a table while reloading by using
    Code (Text):
    1. if not some_tbl then some_tbl = {} end -- a table exist so it's kept
    or
    Code (Text):
    1. some_tbl = some_tbl or {} -- shorter version of thing above
    in code, instead of
    Code (Text):
    1. some_tbl = {} -- information dies when you do /reload
    I feel stupid for not knowing this before and I never saw anyone using it.
    You can make your tables reload-proof this way.
    It doesn't seem to work with "local", though.
     
  2. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,589
    Likes Received:
    1,862
    Best Answers:
    4
  3. LaloHao

    LaloHao Member

    Joined:
    Sep 14, 2008
    Messages:
    73
    Likes Received:
    12
    Best Answers:
    0
    Have you managed to fix this when reloading creaturescripts?

    Example:
    PHP:
    1.  
    2. function onLogin(cid)
    3.       registerCreatureEvent(cid, "lootMessage")
    4.  
    After reloading the events are lost and players need to relogin (or iterate for each player online and reregister the events, but that might lag if it has lot of players)
     

Share This Page

Loading...