252
edits
Legoboyvdlp (talk | contribs) |
(vecindex() details) |
||
Line 2,421: | Line 2,421: | ||
|source = {{simgear file|simgear/nasal/lib.c|t=Source}} | |source = {{simgear file|simgear/nasal/lib.c|t=Source}} | ||
|text = Returns the index of value or nil, if value is not found in vector. | |text = Returns the index of value or nil, if value is not found in vector. | ||
|example1= | |||
var myvector = ["apple", "bananna", "coconut"]; | |||
# to check if a vector contains a certain value compare vecindex to nil | |||
if (vecindex(myvector, "apple") != nil) { | |||
print("found apple"); | |||
} | |||
# WARNING: this will not work as desired because index is 0 | |||
if (vecindex(myvector, "apple")) { | |||
print("found apple"); | |||
} | |||
}} | }} | ||
{{note| There is a similar function function contains(hash, key) to check if a hash contains a key (not value!). | |||
It is to be discussed, if contains can/should be extended to support vectors in the above mentioned way. }} | |||
== Variables == | == Variables == |
edits