Hello All
Another block for me on basic coding. Thank you in advance for being so patient!
Following a previous post I am reworking my text fields as suggested by Klaus. I have a more efficient setup that will make it a lot easier to modify the text fields without having to re-write every line of code.
I have one field that the user ‘clicks’ on a line of text - field “Condition” - to select what condition they want to know how about
Another field has a comma delimited list of information - field “CodeBreaker” e.g. - 24,2,Difficulty turning to one direction,
This information is linked to another field “Correction” that has comma delimited text e.g. - Correction 4: Hamstrings,11,12,13,14, 24,
I want to click on 'Difficulty turning to one direction’ in field “Condition” - (a number of conditions could be selected)
… that will detect that this relates to item 2 of field “Codebreaker” as it has a code of 24 (the 2 is irrelevant for this process, but is used to order another section)
… this relates to line - Correction 4: Hamstrings,11,12,13,14, 24, of field “Correction” - because of the 24 being in this line
I will then combine "Correction 4: Hamstrings" and "Difficulty turning to one direction” elsewhere.
However I am stumped on the first step of getting the condition to find the match with the ‘CodeBreaker”
This is my code for the field “Condition”. The selection line of the script is working fine, so the field “Answer” has lines of text.
put the selection into field “answer” - - so I can see what is going on
repeat for each line theline in field "answer"
if line of theline is among the lines of field "CodeBreaker" then
put this line of field "CodeBreaker" into anothervariable - - the syntax of this line is wrong. I have exhausted my range possible ways to write this, but I know there is a way … there always is with LiveCode
end if
end repeat
Any suggestions will be gratefully received.
regards
Greg
Repeat and lines of text
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Repeat and lines of text
Hi Greg,
from what I gather from your code is that you are searching for the complete line
so you have the line already in the variable theLine.
You can't say "line of theLine" since Livecode expects a valid reference to the address of a line in the variable theLine
Please remember that in
repeat for each line theLine in CONTAINER
livecode loads the content of the line into the variable theLine
Then is the problem of
put this line of field "CodeBreaker" into anothervariable
This is because "is among" tests all lines and returns true as soon as it finds a line that does match. "this line" does not make sense since this and Livecode has no way of knowing what this refers to.
(you could use lineOffset for that -> dictionary)
But in your case it is easy since you test for whole lines and each line theLine is a whole line.
if "is among the lines of CONTAINER" returns true you know you have a match between the content of theLine and any line of field "CodeBreaker"
Now you could put theLine into a variable instead of the identical line of field "CodeBreaker".
A line is just the text of the line and does not include a return character.
You would speed up the whole process if you were not accessing the fields but you would put the content of the fields into variables.
I hope I explainde it well enough.
Kind regards
Bernd
from what I gather from your code is that you are searching for the complete line
Code: Select all
if line of theline is among the lines of field "CodeBreaker" then
You can't say "line of theLine" since Livecode expects a valid reference to the address of a line in the variable theLine
Please remember that in
repeat for each line theLine in CONTAINER
livecode loads the content of the line into the variable theLine
Code: Select all
repeat for each line theline in field "answer"
if theline is among the lines of field "CodeBreaker" then -- this will compile,
put this line of field "CodeBreaker" into anothervariable - - the syntax of this line is wrong. I have exhausted my range possible ways to write this, but I know there is a way … there always is with LiveCode
end if
put this line of field "CodeBreaker" into anothervariable
This is because "is among" tests all lines and returns true as soon as it finds a line that does match. "this line" does not make sense since this and Livecode has no way of knowing what this refers to.
(you could use lineOffset for that -> dictionary)
But in your case it is easy since you test for whole lines and each line theLine is a whole line.
if "is among the lines of CONTAINER" returns true you know you have a match between the content of theLine and any line of field "CodeBreaker"
Now you could put theLine into a variable instead of the identical line of field "CodeBreaker".
A line is just the text of the line and does not include a return character.
You would speed up the whole process if you were not accessing the fields but you would put the content of the fields into variables.
Code: Select all
on mouseUp
put field "answer" into tAnswer
put field "CodeBreaker" into tBreaker
repeat for each line theline in tAnswer
if theline is among the lines of tBreaker then
put theLine into tMyOtherVariable
-- do something with tMyOtherVariable
end if
end repeat
end mouseUp
Kind regards
Bernd
Re: Repeat and lines of text
Thank you Bernd for your very generous reply. I now have a greater understanding of what LC is doing behind the scenes with the repeat control. Your suggestions were very helpful and has also got me to explore the lineOffset function, which has greatly assisted me to work through what I spent yesterday trying to unravel! Thank you so very much.
Regards
Greg
Regards
Greg