it’s maybe because initialize function is empty but i don’t know what i should put here because i already initialize the states with their own function, see
It doesn’t matter if the initialize function is empty. One thing I see is that you didn’t set your initial var correctly in update (var splited_text = …) Same for nb_test and contains_words_searched. So there’s a few thing in your script syntax to review. You can use a tool like jshint.com that may help you.
Also, you can check console log in browser to see any error. I guess that actually, the plugin doesn’t load because the script is not correct.
Well, there’s a typo in line 5 (.lenght means to be .length of course).
Also, properties.words_to_search is not array of texts, it is a List object as described in the documentation (click show documentation link above your Function update text entry area).
You must transform properties.words_to_search into an actual array using the .get() function.
Here’s a generic function for turning List-type properties objects into arrays of whatever type they are (it gets the entire list):
instance.data.funcGetList = function getList(List) {
var returnList = []
if (List.length() < 1) return returnList
returnList = List.get(0, List.length())
return returnList
} // end getList
In terms of the actual logic of your function, BTW, you don’t need those nested for loops. The following one-liner will return true if any of the words in array words is found in the string str:
words.some(word => str.includes(word))
Use it like so:
// our long string of text:
var str = "Hello world, welcome to the universe."
// our array of words we wish to check for in our long string of text:
var words = ['nothing', 'taco', 'welcome']
var is_word_found = words.some(word => str.includes(word))
// is_word_found is true. publish that value to your desired state
If instead words is:
var words = ['nothing', 'taco']
var is_word_found = words.some(word => str.includes(word))
// is_word_found is false