1

I have a random word generation script that works perfectly. I also have a few single character-width fields, exactly the same amount of them as the longest possible word that can be generated. Below each field I have a line that would resemble an underscore. Each field has a unique id, numbered from one like so: "letter1", "letter2".... and so on. Likewise, each line has the id of "line1", "line2", and so on.

Now that I've set the stage, here is what I want to happen. On the opening of the card, I want all of the letter fields to hide as I will have them show individually outside this subroutine. I then want all of the lines to hide, and then only the amount of lines that are required for the random word should show again. (The same number as length(randomword) from left to right.) Now, the random word should be looped through and the first character should be put into the field "letter1", and the second into "letter2", and so on. The word will change each time the card is opened, so it is important that this is not bruteforced (which unfortunately, myself having two weeks experience with LiveCode, is the only thing I know concretely how to do).

Could someone with more experience do me a solid and provide the code I would need to do this, and the location I should put the code in? (the card? the letter fields? I really don't know at this point).

I am happy to provide further description if I have not been articulate about my problem.

Mark
  • 2,380
  • 11
  • 29
  • 49
notHalfBad
  • 213
  • 2
  • 9

2 Answers2

0

Try this (my LiveCode is a bit rusty):

on openCard
   //Put your word generation script here

   put 0 into amtOfLines
   put 0 into amtOfLetters
   repeat until amtOfLines is 6 //Replace 6 with the amount of lines
      add 1 to amtOfLines
      put "line" & amtOfLines into x
      set the visible of graphic x to false
   end repeat
   repeat until amtOfLetters is 6 //Replace 6 with the amount of fields
      add 1 to amtOfLetters
      put "letter" & amtOfLetters into x
      set the visible of field x to false
   end repeat

   put 0 into amtOfLines
   put 0 into amtOfLetters
   repeat until amtOfLines is length(randomword)
      add 1 to amtOfLines
      put "line" & amtOfLines into x
      set the visible of graphic x to true
   end repeat
   repeat until amtOfLetters is length(randomword)
      add 1 to amtOfLetters
      put "letter" & amtOfLetters into x
      set the visible of field x to true
   end repeat

   put 0 into amtOfChars
   repeat until amtOfChars is length(randomword)
      add 1 to amtOfChars
      put "letter" & amtOfChars into x
      set the text of field x to char amtOfChars of randomword
   end repeat
end openCard 

This would go in the card script.

EDIT: Fixed some errors.

atirit
  • 1,492
  • 5
  • 18
  • 30
0

This would go into the card script:

on setup pRandomWord
  put 6 into tNumObjs -- or however many fields there are
  put length(pRandomWord) into tLen
  repeat with x = 1 to tNumObjs
    hide fld ("letter"&x)
    if x <= tLen then
      put char x of pRandomWord into fld ("letter"&x)
      show grc ("line"&x)
    else
      hide grc ("line" & x)
    end if
  end repeat
end setup

When you want to use it, put the random word into a variable and call the setup handler like this:

setup randomWord

This does everything in a single repeat loop. The random word is passed to the setup handler in the parameter "pRandomWord".

Jacque
  • 416
  • 2
  • 7