LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
snm
- VIP Livecode Opensource Backer

- Posts: 253
- Joined: Fri Dec 09, 2011 11:17 am
Post
by snm » Thu Nov 29, 2012 8:11 pm
I need to remove item one in each line of text in variable. I made button with script:
Code: Select all
repeat for each line L in tText
delete item 1 of L
end repeat
In debugger I can see that line L is changing (first item is deleted), but tText doesn't change.
What can be wrong in my code?
Marek
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Nov 29, 2012 9:07 pm
Hi Marek,
"repeat for each..." is insanely fast, but also READ ONLY, which means you cannot modify L (in your case)!
Do something like this:
Code: Select all
...
put fld "whatever holds tText" into tText
repeat for each line L in tText
## Get second to last item:
put item 2 to -1 of L & CR after tNewText
end repeat
## Get rid of trailing CR
delete char -1 of tNewText
put tNewText into fld "whatever holds tText"
...
Best
Klaus
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Thu Nov 29, 2012 9:25 pm
Hi Marek,
Caramba ! Klaus has been faster than me one more.
And his script also: 25 milliseconds.
Code: Select all
on mouseup -- -- 1320 milliseconds
put the milliseconds into old
repeat with i = 1 to 10000
put i & "," & random(100) & cr after tText
end repeat
put 0 into tCount
repeat for each line L in tText
add 1 to tCount
-- delete item 1 of L
delete item 1 of Line tCount of tText
end repeat
put "TimeUsedMilliseconds = " && the milliseconds - old & cr & tText
end mouseup
on mouseup -- 10589 milliseconds
put the milliseconds into old
repeat with i = 1 to 10000
put i & "," & random(100) & cr after tText
end repeat
repeat with i = 1 to the num of lines of tText
delete item 1 of line i of tText
wait 1 milliseconds with messages
end repeat
put "TimeUsedMilliseconds = " && the milliseconds - old & cr & tText -- 10589
end mouseup
Best
Jean-Marc
https://alternatic.ch
-
snm
- VIP Livecode Opensource Backer

- Posts: 253
- Joined: Fri Dec 09, 2011 11:17 am
Post
by snm » Thu Nov 29, 2012 10:05 pm
Thanks a lot Klaus and Jean-Marc.
I was not sure if "repeat for each L ..." Is bug or "red only" - I couldn't find the answer anywhere, so decided to ask you friends.
I started to runaround with Jean-Marc solution, but drop it as slow, asked here and gone home to eat something and go sleep. I was hope to find there solution tomorrow morning, didn't expect such quick answers.
Thanks a lot once more.
Marek
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Thu Nov 29, 2012 11:02 pm
Hi Marek
was not sure if "repeat for each L ..." Is bug or "red only" - I couldn't find the answer anywhere
L is a variable that you can read but that has no effect on tText
Best
Jean-Marc
https://alternatic.ch
-
snm
- VIP Livecode Opensource Backer

- Posts: 253
- Joined: Fri Dec 09, 2011 11:17 am
Post
by snm » Thu Nov 29, 2012 11:29 pm
Hi Jean-Marc,
It's a pity, but now i know that.
Marek
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10330
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Nov 29, 2012 11:42 pm
Hi.
As you have heard, the "repeat for each..." construction is fast.
What you tried to do, and conceptually it was sound, was appropriate for the "repeat with..." construction":
Code: Select all
on mouseUp
repeat with y = 1 to the number of lines of tText
delete item 1 of line y of tText
end repeat
answer tText
end mouseUp
This is straight out of your original intent, which again, was sound, but misapplied to one of LC's several possible repeat options.
Craig Newman