Yes okay, so I can do this kind of iteration in the main function (often I do it that way but sometimes in a function call) and still get cloning not referencing right?
Yeah an old screen shot saved me on my last project ;) One day I would like to get to the bottom of that. I was able to write the JS in a fresh patch carefully testing for parsing as I went and I got it functioning but the exact same text was jamming in another JS patch no matter how much I retyped it. I feel the JS patch is a little illogical at times (as in it gets broken), if that's a good way to put it. Oops, yes recursive is what I meant but it seems to be a regressive move in JS too. On 12 April 2010 01:12, Alastair Leith <[email protected]> wrote: > > > ---------- Forwarded message ---------- > From: Alastair Leith <[email protected]> > Date: 12 April 2010 01:06 > Subject: Re: Javascript issue modifying a structure (again… :/) > To: Christopher Wright <[email protected]> > > > Yes that helps heaps. Thanks cwright. I kind of twigged to the referencing > thing a few weeks back but didn't really extrapolate the general rule (I was > getting some strange results!) and still not 100% sure I have yet. So… > > Does the function you wrote also assign individual item references back to > the original structure? If they are *values* and not *references* put into > *newObj*, is that distinction because of the call to another function or > just the iterating through at the lowest child level of the structure? If > items had sub-items would I need to iterate though sub-items (in more > function calls ? regressive function calls are out in JS aren't they?)? > > So many questions! I'm really grateful for your help already though, thanks > again. > > Alastair > > I guess the downside of a loosely typed language like JS when your trying > to teach yourself scripting (that's me btw ;) ) is that things can get a > little slippery and not generate meaningful error mesages... > > On 12 April 2010 00:49, Christopher Wright <[email protected]> wrote: > >> If anybody could identify my misconception here I be very grateful: >>> >> >> >> You're assuming that you can modify inputs -- you can't. >> >> You're assuming that JS copies by value -- it doesn't (it copies by >> reference). >> >> So, when you assign glyph to an input: glyph = glyphs[cursor]; glyph >> is a reference to the input -- trying to modify that will fail. >> >> You need a copy function, as follows: >> >> function copy(obj) >> { >> var newObj = new Object(); >> for(var e in obj) >> newObj[e] = obj[e]; >> return newObj; >> >> } >> >> cursor = 5; >> function (__structure Glyphs_Out, __boolean Same, __string Font, >> __structure Glyph) >> main (__structure Glyphs_In) >> { >> var result = new Object(); >> var glyph = new Object(); >> var glyphs = new Array(); >> var font = new String(); >> font = "LucidaGrande"; >> if (!_testMode) >> { >> glyphs = Glyphs_In; >> glyph = copy(glyphs[cursor]); >> >> >> // This line works: >> font = glyph.Font_Name; >> glyph.Font_Name = font; >> glyph.Y +=0.1; >> // Can't modify inputs, so you'll have to copy some other >> inputs too. >> //glyphs[cursor]["Y"] +=0.1; >> >> >> result.Font = font; >> result.Glyph = glyph; >> result.Glyphs_Out = glyphs; >> return result >> } >> } >> >> Hope that helps! :) >> >> -- >> [ christopher wright ] >> [email protected] >> http://kineme.net/ >> >> -- >> [ christopher wright ] >> [email protected] >> http://kineme.net/ >> >> > >
_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartzcomposer-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com This email sent to [email protected]

