Re: Collapse (?) An Array?
On 1 Sep 2011, at 10:53, Scott Rossi wrote: Sorry, I don't know the correct verbiage here... If I script this: put A into theArray[1] put B into theArray[2] put C into theArray[3] And then script this: delete variable theArray[2] I essentially get an array with entries that look like this: A C How can I collapse (?) the array after deleting element 2 so that the array only has two elements remaining? A C Scott I think the array is already collapsed. on mouseUp put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] repeat for each element el in theArray put el cr after tOut end repeat put tOut end mouseUp This gives: A C What are you doing to get A C Dave ___ 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
Re: Collapse (?) An Array?
Try this in the multiline message box: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *theArray[2] * theArray[3] You'll see that although theArray[2] is deleted, its position is still kept. The way the dictionary describes it suggests that the element would have been removed. On Sep 1, 2011, at 7:27 AM, Dave Cragg wrote: What are you doing to get A C ___ 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
Re: Collapse (?) An Array?
On 1 Sep 2011, at 13:13, Colin Holgate wrote: Try this in the multiline message box: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *theArray[2] * theArray[3] You'll see that although theArray[2] is deleted, its position is still kept. The way the dictionary describes it suggests that the element would have been removed. I don't really see it as its position being kept. For example, this will produce the same result: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *theArray[7] * theArray[3] It seems using any key on an existing array will produce an empty value. (I don't know if that's how it should behave. I guess the alternative would be throwing an error.) The following suggests the array position has indeed been deleted: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put the keys of theArray Cheers Dave ___ 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
Re: Collapse (?) An Array?
On 1 Sep 2011, at 14:16, Dave Cragg wrote: It seems using any key on an existing array will produce an empty value. (I don't know if that's how it should behave. I guess the alternative would be throwing an error.) Update: it seems the array doesn't even need to exist. This also produces the same result: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *otherArray[7] * theArray[3] Cheers Dave ___ 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
Re: Collapse (?) An Array?
I totally get what the OP wants, code-wise, I just cannot help make it happen, but perhaps I can put it in my terms and help someone more knowledgeable than me help him. What he is saying, is that when a variable is deleted from within the array, he needs the entire array re-ordered (sorted) and moved up a notch to account for the now deleted variable. So, if A,B,C,D is the array with positions 1,2,3,4 and you delete array variable 2 It will now look like this: A,C,D and the array numbers are now: 1,3,4 He needs it to be A,C,D and 1,2,3 The C is now 2 and the D is now 3, so on and so forth across however large the array is. Now, does one simply re-write the array once the deletion is made? Not sure. Note - if this is for a database and you are dealing with IDs, then DO NOT RE-ORDER ANYTHING - you will break the database (well, not literally until you do a SAVE - then you really will break it). Just leave it as is. Databases can eventually be re-ordered (re-indexed) once they are too large and riddled with holes, but until then, just leave it alone. Mike On Thu, 1 Sep 2011 14:27:44 +0100, Dave Cragg wrote: On 1 Sep 2011, at 14:16, Dave Cragg wrote: It seems using any key on an existing array will produce an empty value. (I don't know if that's how it should behave. I guess the alternative would be throwing an error.) Update: it seems the array doesn't even need to exist. This also produces the same result: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *otherArray[7] * theArray[3] Cheers Dave ___ use-livecode mailing list use-livecode@lists.runrev.com [1] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode [2] Links: -- [1] mailto:use-livecode@lists.runrev.com [2] http://lists.runrev.com/mailman/listinfo/use-livecode ___ 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
Re: Collapse (?) An Array?
Scott Rossi wrote: If I script this: put A into theArray[1] put B into theArray[2] put C into theArray[3] And then script this: delete variable theArray[2] I essentially get an array with entries that look like this: A C How can I collapse (?) the array after deleting element 2 so that the array only has two elements remaining? A C The delete is fine; the problem is in the display of the results. If you use: put theArray[1] *theArray[2] * theArray[3] ...you'll get the empty entry for theArray[2]. The variable theArray still exists, but there's nothing in that slot. Building the output from the keys of the array will get what you want: put the keys of theArray into tKeys sort lines of tKeys -- if the order is important repeat for each line tKey in tKeys put * theArray[tKey] after tResult end repeat put tResult -- Richard Gaskin Fourth World LiveCode training and consulting: http://www.fourthworld.com Webzine for LiveCode developers: http://www.LiveCodeJournal.com LiveCode Journal blog: http://LiveCodejournal.com/blog.irv ___ 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
Re: Collapse (?) An Array?
I think Mike's explanation over complicated things! I now understand what Dave was saying, and the problem stems from us humans reading a 1 as an index into the array, and not a key of the array. In other languages you could say: put hello into theArray[10] and that array would now have ten entries, nine of which haven't been filled in yet. In an LC array, there is only one entry, and its key is 10, and the value is hello. ___ 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
Re: Collapse (?) An Array?
On 1 Sep 2011, at 14:48, Admin wrote: So, if A,B,C,D is the array with positions 1,2,3,4 and you delete array variable 2 It will now look like this: A,C,D and the array numbers are now: 1,3,4 He needs it to be A,C,D and 1,2,3 Looking back, I guess that's what Scott was hoping for. (I'm sure he'll pipe in to confirm.) Unfortunately (or perhaps not), it doesn't work that way. Livecode arrays are associative arrays, and all keys, whether numbers or strings, behave in the same way. Dave ___ 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
Re: Collapse (?) An Array?
Collin, Perhaps to you I was over complicating things, but as I see it, that is what he was asking for. If you have nothing nice to say . . . Mike P.S. I am not an admin - when I joined the live code summer academy, they auto-assigned this forum name to me - it's not by my choice. On Thu, 1 Sep 2011 14:59:55 +0100, Dave Cragg wrote: On 1 Sep 2011, at 14:48, Admin wrote: So, if A,B,C,D is the array with positions 1,2,3,4 and you delete array variable 2 It will now look like this: A,C,D and the array numbers are now: 1,3,4 He needs it to be A,C,D and 1,2,3 Looking back, I guess that's what Scott was hoping for. (I'm sure he'll pipe in to confirm.) Unfortunately (or perhaps not), it doesn't work that way. Livecode arrays are associative arrays, and all keys, whether numbers or strings, behave in the same way. Dave ___ use-livecode mailing list use-livecode@lists.runrev.com [1] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode [2] Links: -- [1] mailto:use-livecode@lists.runrev.com [2] http://lists.runrev.com/mailman/listinfo/use-livecode ___ 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
Re: Collapse (?) An Array?
Recently, Richard Gaskin wrote: The delete is fine; the problem is in the display of the results. If you use: put theArray[1] *theArray[2] * theArray[3] ...you'll get the empty entry for theArray[2]. The variable theArray still exists, but there's nothing in that slot. Yes, this is the problem. I'm storing data in array form in custom properties, and my problem is after a delete, the remaining elements of the array are not reordered. Building the output from the keys of the array will get what you want: put the keys of theArray into tKeys sort lines of tKeys -- if the order is important repeat for each line tKey in tKeys put * theArray[tKey] after tResult end repeat put tResult From what you're saying, it sounds like I need to put the remaining elements of the array into a temporary variable and then replace the original array. Regards, Scott Rossi Creative Director Tactile Media, UX Design ___ 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
Re: Collapse (?) An Array?
Yes, the I think part of what I said meant that to me it had over complicated things. Glad to hear that it was easy to understand for the others, and at least I had the personal breakthrough of realizing that anArray[10] doesn't refer to the tenth position of an array. On Sep 1, 2011, at 10:06 AM, Admin wrote: Perhaps to you I was over complicating things, but as I see it, that is what he was asking for. ___ 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
Re: Collapse (?) An Array?
On 9/1/11 9:10 AM, Scott Rossi wrote: From what you're saying, it sounds like I need to put the remaining elements of the array into a temporary variable and then replace the original array. If that's what you need, then it might be easier to just combine the array, remove the line you don't want, and then split it again. If any of your values are more than one line, use custom delimiters that don't appear in your data anywhere. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ 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
Re: Collapse (?) An Array?
On Thu, Sep 1, 2011 at 12:18 PM, J. Landman Gay jac...@hyperactivesw.comwrote: On 9/1/11 9:10 AM, Scott Rossi wrote: From what you're saying, it sounds like I need to put the remaining elements of the array into a temporary variable and then replace the original array. If that's what you need, then it might be easier to just combine the array, remove the line you don't want, and then split it again. If any of your values are more than one line, use custom delimiters that don't appear in your data anywhere. on foldArray @pA combine pA by numtochar(4) split pA by numtochar(4) end foldArray This works right??? -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com __**_ 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-livecodehttp://lists.runrev.com/mailman/listinfo/use-livecode -- http://www.andregarzia.com All We Do Is Code. ___ 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
Re: Collapse (?) An Array?
Recently, Jacque Landman Gay wrote: From what you're saying, it sounds like I need to put the remaining elements of the array into a temporary variable and then replace the original array. If that's what you need, then it might be easier to just combine the array, remove the line you don't want, and then split it again. If any of your values are more than one line, use custom delimiters that don't appear in your data anywhere. Funny, the whole reason I'm using arrays to store custom properties is to avoid relying on delimiter characters :-) I'm storing image data which has all kinds of crazy characters and don't want to risk corrupting the images. I was hoping there was some special combine/split/union (collapse!) command that would do what I needed, but rebuilding the array is working fine so far. Thanks to all who responded. And Mike Admin, yes, you understood what I was asking for. Regards, Scott Rossi Creative Director Tactile Media, UX Design ___ 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
Re: Collapse (?) An Array?
Scott Rossi wrote: Recently, Richard Gaskin wrote: The delete is fine; the problem is in the display of the results. If you use: put theArray[1] *theArray[2] * theArray[3] ...you'll get the empty entry for theArray[2]. The variable theArray still exists, but there's nothing in that slot. Yes, this is the problem. I'm storing data in array form in custom properties, and my problem is after a delete, the remaining elements of the array are not reordered. True, the order of elements in an associative array is not maintained across split and combine, but within the array there is no order per se, just a set of slots that point to memory locations. If order is important you'll want to use the sort command on the array keys and access them in that sorted order. Building the output from the keys of the array will get what you want: put the keys of theArray into tKeys sort lines of tKeys -- if the order is important repeat for each line tKey in tKeys put * theArray[tKey] after tResult end repeat put tResult From what you're saying, it sounds like I need to put the remaining elements of the array into a temporary variable and then replace the original array. Not at all. The array's fine. All you need to do is tailor your output according to your needs. It may be helpful to remember that all arrays in LiveCode are associative arrays. Any keys you use are strings, whether comprised of alphanumeric or strictly numeric characters. The slots in an associative array aren't numbered per se, they're named. Using the keys of the array will show you which names are in use, and they can be sorted to get any output you need. -- Richard Gaskin Fourth World LiveCode training and consulting: http://www.fourthworld.com Webzine for LiveCode developers: http://www.LiveCodeJournal.com LiveCode Journal blog: http://LiveCodejournal.com/blog.irv ___ 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
Re: Collapse (?) An Array?
I can put put theArray[2] into the message box and get empty, and I do not even HAVE an array called theArray! :-) Bob On Sep 1, 2011, at 5:13 AM, Colin Holgate wrote: Try this in the multiline message box: put A into theArray[1] put B into theArray[2] put C into theArray[3] delete variable theArray[2] put theArray[1] *theArray[2] * theArray[3] You'll see that although theArray[2] is deleted, its position is still kept. The way the dictionary describes it suggests that the element would have been removed. On Sep 1, 2011, at 7:27 AM, Dave Cragg wrote: What are you doing to get A C ___ 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 ___ 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
Re: Collapse (?) An Array?
Try instead: put the keys of theArray into myKeys put 2 is in myKeys See what you get. Bob On Sep 1, 2011, at 2:53 AM, Scott Rossi wrote: Sorry, I don't know the correct verbiage here... If I script this: put A into theArray[1] put B into theArray[2] put C into theArray[3] And then script this: delete variable theArray[2] I essentially get an array with entries that look like this: A C How can I collapse (?) the array after deleting element 2 so that the array only has two elements remaining? A C Thanks for suggestions. Regards, Scott Rossi Creative Director Tactile Media, UX Design ___ 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 ___ 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