simple trick - making a table /reload proof

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

  1. zbizu

    zbizu Retired

    Joined:
    Nov 22, 2010
    Messages:
    2,440
    Likes Received:
    1,352
    Best Answers:
    1
    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.
     
    Joe Rod, Killua Real, Static_ and 2 others like this.
  2. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,604
    Likes Received:
    1,910
    Best Answers:
    5
  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)
     
  4. 5lave Ots

    5lave Ots Member

    Joined:
    Oct 2, 2017
    Messages:
    33
    Likes Received:
    3
    Best Answers:
    0
    maybe
    Code (Text):
    1. function onThink(cid, Interval)
    2.       registerCreatureEvent(cid, "lootMessage")
    3. end
     

Share This Page

Loading...