Slight fix to the code: if x < x1 and abs(x1 - x) >= abs(y1 - y) and d < nxtd and the lastbtn of btn b < 1 then
Needed to make sure the button wasn't already used in the previous line. ~ Chris Innanen ~ Nonsanity On Mon, Jan 31, 2011 at 2:00 PM, form <f...@nonsanity.com> wrote: > I'm thinking you're going for refrigerator poetry magnets, or something > like it. To that end, I made something that reads the order similar to the > way a human would. I haven't tested it a lot, but this was the arrangement I > used: > > http://dl.dropbox.com/u/144280/btnorder.png > > There are a dozen buttons, named with their btn number. (So button 6 is > named "6".) Notice that word 8 is at about the same level as word 9, but > still counts as part of the second row. > > Running the following script sets properties on all the buttons (and one on > the card) that lets you easily walk through them from other scripts. The > scanrwords command needs to be re-run after moving the buttons, but only > then. > > The last chunk of the scanwords command does a sample walkthrough and > outputs the buttons in "word" order to the messagebox. Use that code in > other functions that need to move through the words. > > > on scanwords > -- clear the custom properties > repeat with a = 1 to the number of btns > set the nextbtn of btn a to "0" > set the lastbtn of btn a to "0" > set the startsline of btn a to "0" > set the linenumber of btn a to "0" > set the nextline of btn a to "0" > end repeat > > repeat with a = 1 to the number of btns > put item 1 of the loc of btn a into x > put item 2 of the loc of btn a into y > put "" into nxtbtn > put 100000000 into nxtd > repeat with b = 1 to the number of btns > if a = b then next repeat > put dist( loc of btn a, loc of btn b ) into d > put item 1 of the loc of btn b into x1 > put item 2 of the loc of btn b into y1 > if x < x1 and abs(x1 - x) >= abs(y1 - y) and d < nxtd then > put d into nxtd > put b into nxtbtn > end if > end repeat > if nxtbtn is not empty then > set the nextbtn of btn a to nxtbtn > set the lastbtn of btn nxtbtn to a > end if > end repeat > > put "" into sortlines > repeat with a = 1 to the number of btns > if the lastbtn of btn a < 1 > then put item 2 of the loc of btn a &","& a & return after sortlines > end repeat > sort lines of sortlines numeric by item 1 of each > repeat with a = 1 to the number of lines in sortlines > set the startsline of btn (item 2 of line a of sortlines) to a > end repeat > > set the firstbtn of this card to item 2 of line 1 of sortlines > put 0 into lasttgt > repeat with a = 1 to the number of lines in sortlines > put item 2 of line a of sortlines into tgt > set the linenumber of btn tgt to a > if lasttgt > 0 then set the nextline of btn lasttgt to tgt > put the short name of btn tgt &"," after output > put tgt into lasttgt > put the nextbtn of btn tgt into tgt > repeat while tgt > 0 > set the linenumber of btn tgt to a > put the short name of btn tgt &"," after output > put tgt into lasttgt > put the nextbtn of btn tgt into tgt > end repeat > end repeat > > -- all buttons are now tagged with the information needed to read them > -- the first button is in the firstbtn of this card > -- buttons that start a new line have a startsline property of the line > they start > -- the line each button is on is in its linenumber property > -- the nextbtn and lastbtn point to the next and last button in that > line, respectively > -- buttons at the end of a line have a nextline property with > -- the number of the next line's first button > > -- output the "words" in order to the msg box > put "" into output > put the firstbtn of this card into tgt > repeat while tgt > 0 > put tgt &"," after output > get the nextbtn of btn tgt > if it < 1 then get the nextline of btn tgt > put it into tgt > end repeat > delete last char of output > put output into msg > end scanwords > > > function dist a, b > return sqrt( (item 1 of b - item 1 of a)*(item 1 of b - item 1 of a) + > (item 2 of b - item 2 of a)*(item 2 of b - item 2 of a) ) > end dist > > > ~ Chris Innanen > ~ Nonsanity > > _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode