get_hudbar_state: return nil if not initialized

master
flux 2023-06-20 12:42:50 -07:00
parent 965a67a9c1
commit 881564d441
No known key found for this signature in database
GPG Key ID: 9333B27816848A15
2 changed files with 2 additions and 1 deletions

2
API.md
View File

@ -187,7 +187,7 @@ Makes a previously hidden HUD bar visible again to a player.
It is also possible to read information about existing HUD bars.
### `hb.get_hudbar_state(player, identifier)`
Returns the current state of the active player's HUD bar.
Returns the current state of the active player's HUD bar. Will return `nil` if the hudbar is not initialized.
#### Parameters
* `player`: `ObjectRef` of the player to which the HUD bar belongs to

View File

@ -446,6 +446,7 @@ end
function hb.get_hudbar_state(player, identifier)
if not player_exists(player) then return nil end
local ref = hb.get_hudtable(identifier).hudstate[player:get_player_name()]
if not ref then return nil end
-- Do not forget to update this chunk of code in case the state changes
local copy = {
hidden = ref.hidden,