I looked at this post and I get a warning when I do what they said to do in the answer, it says.
I am wondering if there is a way that I can get rid of this warning?
local exampleTable = {}
if exampleTable.exampleFunction then
exampleTable.ExampleFunction()
end
Can you post your script so we can better help you?
I will give an example, but this is for purely knowledge not a large scale script
I edited my post, does this clarify my question?
blokav
(blokav)
December 24, 2020, 2:10am
#5
local exampleTable = {}
if typeof(exampleTable.exampleFunction) == "function" then
exampleTable.exampleFunction()
end
typeof() will return “nil” if exampleFunction isn’t there or something else if it’s a different data type.
That still gives me the same warning, thanks anyway.
blokav
(blokav)
December 24, 2020, 2:11am
#7
What does the warning say?
To clarify, the above code works, it just displays a warning, and if I have hundreds of those, well those warns would get annoying.
It’s on the top of the post, but here it is anyway
blokav
(blokav)
December 24, 2020, 2:13am
#10
That’s just the syntax highlighter; there shouldn’t be any error/warning at run-time.
But hundreds of those, definitely gets annoying and if I have all types of those things…
blokav
(blokav)
December 24, 2020, 2:15am
#12
You should probably fix them then, just to keep your code clean. If “exampleFunction” is meant to be defined later then you could just put a placeholder value when you define “exampleTable” in order to silence the warning.
The warning is showing because in the script you are indexing a key that isn’t hard-coded in the table; it’s confusing the syntax checker.
Operatik
(Operatik)
December 24, 2020, 10:00am
#13
Alternatively, to silence this, you can use square brackets and use the matching name in a string into the brackets to find it.
3 Likes