set the_question to the content of text field "the_box" of window "main"
if the_question contains "will" then set listOf to {"No", "Yes", "Never", "Maybe"}
if the_question contains " " then set listOf to {"Ask Me a Question, and I will tell you no lies"}
if the_question contains {"pot", "kill", "destroy", "drug", "drugs", "killing"} then set listOf to {"no", "never", "don't event try"}
if the_question contains "how" then set listOf to {"With much preperation", "Very Carefully", "May be you shouldn't", "Don't just party like its 1699"}
set the_fortune to (item (random number from 1 to (length of listOf)) of listOf)
say "" & the_fortune & ""
display dialog "" & the_fortune & "" buttons {"Ok"} default button 1
the problem is on line 4
it doesnt seem to test any of the items in the list
so how do i get it to test for items in the list??
How many times are we going to go over compound if-then-else statements? Also, you can’t test whether a string contains a list of substrings at once, you need to break that down into individual tests. You also don’t need so many tests because if you test for “kill” then, inherently, that test also encompasses “killing”. I find “some item” to be easier than random numbers. And, finally, there is no need to bracket your strings with double quotes. You’d only do that at the beginning if the value you wanted to coerce to a string wasn’t already a string. In this case, you’re only dealing with strings so no coercions are necessary. So, with that, try this:
if the_question contains "will" then
set listOf to {"No", "Yes", "Never", "Maybe"}
else if the_question contains " " then
set listOf to {"Ask Me a Question, and I will tell you no lies"}
else if the_question contains "pot" then
set listOf to {"no", "never", "don't event try"}
else if the_question contains "kill" then --killing contains kill so it's superflous
set listOf to {"no", "never", "don't event try"}
else if the_question contains "destroy" then
set listOf to {"no", "never", "don't event try"}
else if the_question contains "drug" then --drugs contains drug so it's superflous
set listOf to {"no", "never", "don't event try"}
else if the_question contains "how" then
set listOf to {"With much preperation", "Very Carefully", "May be you shouldn't", "Don't just party like its 1699"}
end if
set the_fortune to (some item of listOf)
say the_fortune
display dialog the_fortune buttons {"Ok"} default button 1
Also, you can use a repeat loop to find a word in the text. Something like this or a variation of this:
set user_words to every word of "I like drugs."
set the_list to {"pot", "kill", "destroy", "drug", "drugs", "killing"}
set the_flag to false
repeat with this_word in the_list
if this_word is in user_words then
set the_flag to true
exit repeat
end if
end repeat
if the_flag then
say "boooooooo" & space & this_word
else
say "alright!"
end if