Repeat and Arrays
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 4
- Joined: Tue Jul 24, 2012 2:43 am
Repeat and Arrays
I have been dabbling with Live Code for a while now, but can never figure out how to maximize the use of "repeat" and "arrays." What I am trying to do is to calculate the sum of a word, based on letter values, for each word in a list and then populate the value in an adjacent column.
My approach
Repeat for each word in list 1~n,
Put first word into an array,
Repeat for each letter in word
Put each letter into a nested array,
Assign a value to each letter (If A=1 then put 1 into tNestedArray(Char1) / else if B=4 then put 4 into tNestedArray(Char 1), etc end if(I think that I need to create a function or custom property))
Sum the values to each letter,
Then tab and put a value as item 2
end repeat for each letter
end repeat for each word
My code so far:
if script don't work again then
put computer in trash
end if
Help is needed.
Cheers!
My approach
Repeat for each word in list 1~n,
Put first word into an array,
Repeat for each letter in word
Put each letter into a nested array,
Assign a value to each letter (If A=1 then put 1 into tNestedArray(Char1) / else if B=4 then put 4 into tNestedArray(Char 1), etc end if(I think that I need to create a function or custom property))
Sum the values to each letter,
Then tab and put a value as item 2
end repeat for each letter
end repeat for each word
My code so far:
if script don't work again then
put computer in trash
end if
Help is needed.
Cheers!
Re: Repeat and Arrays
Hi,
This script assumes that you have one word on each line in field x. It also needs a second field y.
Kind regards,
Mark
This script assumes that you have one word on each line in field x. It also needs a second field y.
Code: Select all
on mouseUp
put fld x into myList
repeat for each line myWord in myList
put 0 into myWordValue
repeat for each char myChar in myWord
add valueForChar(myChar) to myWordValue
end repeat
put myWordValue into myNewArray[myWord]
end repeat
combine myNewArray by return and tab
put myNewArray into fld y
end mouseUp
function valueForChar theChar
// do this yourself
end valueForChar
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 4
- Joined: Tue Jul 24, 2012 2:43 am
Re: Repeat and Arrays
Mark,
Thank you so much... I am going to try it first thing this morning.
Great Regards.
Thank you so much... I am going to try it first thing this morning.
Great Regards.
Re: Repeat and Arrays
Mark. W.F
I think there is a typo in the script. Change "line" to "word" in:
repeat for each line myWord in myList
Craig Newman
I think there is a typo in the script. Change "line" to "word" in:
repeat for each line myWord in myList
Craig Newman
Re: Repeat and Arrays
Craig, afaik there is a list of words, one word per line. The script should make sense as I wrote it. I'd expect OP to adjust the script anyway. Maybe s/he'll decide to make the change you suggest.
Kind regards,
Mark
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 4
- Joined: Tue Jul 24, 2012 2:43 am
Re: Repeat and Arrays
Craig and Mark,
First, thank you both for your quick responses.
I ran it both ways (repeat for each line myWord in myList; and, repeat for each word myWord in myList)... and both ways return the same results.
Again... I greatly appreciate it!!!
Bill
First, thank you both for your quick responses.
I ran it both ways (repeat for each line myWord in myList; and, repeat for each word myWord in myList)... and both ways return the same results.
Again... I greatly appreciate it!!!
Bill
Re: Repeat and Arrays
Mark.
Seems you were right. ..."each word in a list..." meant one word per line
Craig
Seems you were right. ..."each word in a list..." meant one word per line
Craig