Copy Contents of one Field to Another

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

Post Reply
Bantymom
Posts: 73
Joined: Fri Aug 27, 2010 4:32 am

Copy Contents of one Field to Another

Post by Bantymom » Mon Aug 30, 2010 8:57 am

Hello again...

Yes, I'm stuck again.

My game now creates a list of words to show to the children to spell. As they spell a word correctly, that word is deleted from the list.

Here is the code for that part:

on RunGame
put 0 into gAttempts
get any word of field "TempList" of card "List Card"
put it into gWord

move field "word" to the loc of gButton in 1 tick
set the locktext of field "word" to true
put gWord into field "word"
show field "word"
wait 2 seconds
put empty into field "word"

set the locktext of field "word" to false
click at the loc of field "word"
end RunGame

on returnInField
put field "word" into tAnswer
--that is the word the students typed into the field, which is then compared to the original word
select empty
if tAnswer = gWord then
put yes into field "word"
hide button gButton
hide field "word" -- this with the above reveal a piece of the picture
replace gWord with empty in field "List 1" of card "List Card"
--removes the word from the list, but delets parts of other words that match as well!

I was using "any" because it seemed the easiest way to randomize the word selection but it looks like I will have to randomize a number and ask for a word by number instead, then after deleting that word, move up the other words and select a random number from 1-19 instead of from 1-20. It would be easier, however, if I could instead delete only whole words instead of parts of words.

Suggestions?

*sets out chocolate-chip cookies as a bribe*

Thanks,
Banty
2nd-grade Teacher, Poultry Fancier, Scottish Country Dancer
and Perpetual Beginner

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Copy Contents of one Field to Another

Post by bn » Mon Aug 30, 2010 10:28 am

Bantymom,

instead of

Code: Select all

replace gWord with empty in field "List 1" of card "List Card"
put this

Code: Select all

 put wordOffset(gWord,field "List 1") into tWordNumber
put empty into word tWordNumber of field "List 1"
this assumes that you only have unique words "in List 1", multiple occurences of a word would be a little different.
--removes the word from the list, but delets parts of other words that match as well!
that is a very useful aspect of replace, it just does not work if you want to operate on words
regards
Bernd

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Copy Contents of one Field to Another

Post by Mark » Mon Aug 30, 2010 12:45 pm

Hi,

Here's a simple routine to delete all words gWord from a field.
lock screen
repeat with x = number of words of fld "Word List" down to 1
if word x of fld "Word List" is gWord then
delete word x of fld "Word List"
end if
end repeat
unlock screen
Best,

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

Post Reply