@@ -40,31 +40,31 @@ function Player.additional_data(...)
4040 return Player
4141end
4242
43- --- Get `game.players[index]` & `global .players[index]`, or create `global .players[index]` if it doesn't exist.
43+ --- Get `game.players[index]` & `storage .players[index]`, or create `storage .players[index]` if it doesn't exist.
4444-- @tparam number|string|LuaPlayer player the player index to get data for
4545-- @treturn LuaPlayer the player instance
46- -- @treturn table the player's global data
46+ -- @treturn table the player's storage data
4747-- @usage
4848-- local Player = require('__stdlib__/stdlib/event/player')
4949-- local player, player_data = Player.get(event.player_index)
5050function Player .get (player )
5151 player = Game .get_player (player )
52- return player , global .players and global .players [player .index ] or Player .init (player .index )
52+ return player , storage .players and storage .players [player .index ] or Player .init (player .index )
5353end
5454
5555--- Get the players saved data table. Creates it if it doesn't exsist.
5656-- @tparam number index The player index to get data for
57- -- @treturn table the player's global data
57+ -- @treturn table the player's storage data
5858function Player .pdata (index )
59- return global .players and global .players [index ] or Player .init (index )
59+ return storage .players and storage .players [index ] or Player .init (index )
6060end
6161
62- --- Merge a copy of the passed data to all players in `global .players`.
62+ --- Merge a copy of the passed data to all players in `storage .players`.
6363-- @tparam table data a table containing variables to merge
6464-- @usage local data = {a = 'abc', b = 'def'}
6565-- Player.add_data_all(data)
6666function Player .add_data_all (data )
67- local pdata = global .players
67+ local pdata = storage .players
6868 table .each (
6969 pdata ,
7070 function (v )
7676--- Remove data for a player when they are deleted.
7777-- @tparam table event event table containing the `player_index`
7878function Player .remove (event )
79- global .players [event .player_index ] = nil
79+ storage .players [event .player_index ] = nil
8080end
8181
8282--- Init or re-init a player or players.
8383-- Passing a `nil` event will iterate all existing players.
8484-- @tparam [opt] number|table|string|LuaPlayer event
8585-- @tparam [opt=false] boolean overwrite the player data
8686function Player .init (event , overwrite )
87- -- Create the global .players table if it doesn't exisit
88- global .players = global .players or {}
87+ -- Create the storage .players table if it doesn't exisit
88+ storage .players = storage .players or {}
8989
9090 -- get a valid player object or nil
9191 local player = Game .get_player (event )
9292
9393 if player then -- If player is not nil then we are working with a valid player.
94- if not global .players [player .index ] or (global .players [player .index ] and overwrite ) then
95- global .players [player .index ] = new (player .index )
96- return global .players [player .index ]
94+ if not storage .players [player .index ] or (storage .players [player .index ] and overwrite ) then
95+ storage .players [player .index ] = new (player .index )
96+ return storage .players [player .index ]
9797 end
9898 else -- Check all players
9999 for index in pairs (game .players ) do
100- if not global .players [index ] or (global .players [index ] and overwrite ) then
101- global .players [index ] = new (index )
100+ if not storage .players [index ] or (storage .players [index ] and overwrite ) then
101+ storage .players [index ] = new (index )
102102 end
103103 end
104104 end
105105
106- if global ._print_queue then
106+ if storage ._print_queue then
107107 table .each (
108- global ._print_queue ,
108+ storage ._print_queue ,
109109 function (msg )
110110 game .print (tostring (msg ))
111111 end
112112 )
113- global ._print_queue = nil
113+ storage ._print_queue = nil
114114 end
115115 return Player
116116end
0 commit comments