Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Sun Jan 25, 2015 8:37 pm
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
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sun Jan 25, 2015 8:55 pm
Did you forget to put the contents of the text file into the gSentence variable?
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Sun Jan 25, 2015 8:59 pm
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
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
-
Contact:
Post
by dave.kilroy » Sun Jan 25, 2015 9:24 pm
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
"...this is not the code you are looking for..."
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Sun Jan 25, 2015 11:15 pm
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.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
-
Contact:
Post
by dave.kilroy » Sun Jan 25, 2015 11:57 pm
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
"...this is not the code you are looking for..."
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Mon Jan 26, 2015 12:04 am
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.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
-
Contact:
Post
by dave.kilroy » Mon Jan 26, 2015 12:34 am
Hi Shawnblc - hmm can't think what else to suggest without seeing your stack...
"...this is not the code you are looking for..."
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Mon Jan 26, 2015 1:03 am
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
-
shawnblc
- VIP Livecode Opensource Backer

- Posts: 342
- Joined: Fri Jun 01, 2012 11:11 pm
Post
by shawnblc » Mon Jan 26, 2015 2:27 am
Let me do a little more testing, but I think I got it now Dave. Thanks. Will update.
UPDATE: NOPE! I won't rest!