Skip to content

Commit 7191743

Browse files
authored
Added HasData()
Added a new function to be able to check if data has been already saved by the provided key. Unlike GetData(), HasData() will not throw an exception if the customData table has not been created yet.
1 parent 521efed commit 7191743

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

QueryArray.nut

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ class csQuery.QueryArray {
115115
return this;
116116
}
117117

118+
function HasData(key) {
119+
local env = { key = key, hasData = false }
120+
this.Each(function (ent) {
121+
ent.ValidateScriptScope();
122+
local scope = ent.GetScriptScope();
123+
if (!("customData" in scope))
124+
return;
125+
126+
if (key in scope.customData)
127+
hasData = true;
128+
}.bindenv(env));
129+
return env.hasData;
130+
}
131+
118132
function GetData(key) {
119133
return getData(false, key)
120134
}

0 commit comments

Comments
 (0)