Page 1 of 1

[Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 8:37 pm
by shawnblc
I'm trying to only proceed (mark correct) if word 2 is on the same line as word 1. Believe it or not, I had this working the other day, but can't find my code in the hundreds of little practice stacks I have.


In a button

Code: Select all

  if tWord is among the words of gSentence and word 2 of gSentence is "Scooby-Doo" then

.....
In my text file

Code: Select all

Dog   Scooby-Doo

Re: [Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 8:55 pm
by SparkOut
Did you forget to put the contents of the text file into the gSentence variable?

Re: [Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 8:59 pm
by shawnblc
SparkOut wrote:Did you forget to put the contents of the text file into the gSentence variable?
No. I put URL "http://domain.com/testfile.txt" into gSentence

Re: [Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 9:24 pm
by dave.kilroy
Hi shawnblc - you don't appear to be putting a value into tWord in order to make valid comparisons - so use something like this:

Code: Select all

   repeat for each word tWord in gSentence
        if tWord is among the words of gSentence and word 2 of gSentence is "Scooby-Doo" then put true into tContains
   end repeat
   answer tContains

Re: [Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 11:15 pm
by shawnblc
dave.kilroy wrote:Hi shawnblc - you don't appear to be putting a value into tWord in order to make valid comparisons - so use something like this:

Code: Select all

   repeat for each word tWord in gSentence
        if tWord is among the words of gSentence and word 2 of gSentence is "Scooby-Doo" then put true into tContains
   end repeat
   answer tContains
Thanks Dave. Seems to hang up LC on my setup, I have to force quit LC. Running 7.0.2 rc 1 build 10024, on OSX Yosemite 10.10.1.

I guess it could be that my text file is a thousand lines, but without the repeat I can find tWord in a split.

Re: [Beginner] Is among and word 2

Posted: Sun Jan 25, 2015 11:57 pm
by dave.kilroy
Ah if you're using split you are creating an array and maybe should be dealing with elements rather than words - exactly how are you populating your variables?

A 'repeat for each' should be pretty fast and by no means should mean you have to force quite LiveCode - are you by any chance reading the text file one at a time rather than putting it into a variable? Something strange appears to be going on with your code, maybe give more background or ideally more code...

Kind regards

Dave

Re: [Beginner] Is among and word 2

Posted: Mon Jan 26, 2015 12:04 am
by shawnblc
dave.kilroy wrote:Ah if you're using split you are creating an array and maybe should be dealing with elements rather than words - exactly how are you populating your variables?

A 'repeat for each' should be pretty fast and by no means should mean you have to force quite LiveCode - are you by any chance reading the text file one at a time rather than putting it into a variable? Something strange appears to be going on with your code, maybe give more background or ideally more code...

Kind regards

Dave
Putting the text file into a global variable.

Re: [Beginner] Is among and word 2

Posted: Mon Jan 26, 2015 12:34 am
by dave.kilroy
Hi Shawnblc - hmm can't think what else to suggest without seeing your stack...

Re: [Beginner] Is among and word 2

Posted: Mon Jan 26, 2015 1:03 am
by shawnblc

Code: Select all

   if tWord is among the words of gSentence and word 2 of gSentence is "Scooby-Doo" then
      set the visible of img "imgRed" to false

.....
Everything works UNTIL I want to add word 2 of gSentence

Re: [Beginner] Is among and word 2

Posted: Mon Jan 26, 2015 2:27 am
by shawnblc
Let me do a little more testing, but I think I got it now Dave. Thanks. Will update.

UPDATE: NOPE! I won't rest!