altID

Dick Kriesel dick.kriesel at mail.com
Sat May 26 14:37:31 EDT 2007


On 5/26/07 3:51 AM, "David Bovill" <david at openpartnership.net> wrote:

> I like the idea of being able to copy a template
> into a stack and still refer to the object by its altID - so everything
> keeps working. The aim is not to have to rename anything in a script as this
> gets messy in a general case.
> 
> But if I copy 10 versions to the same stack it won't work with altIDs
> because they would all have the same id and as (unlike the case with normal
> ids) - you cant use a syntax like "group id 65535 of card 1" there is no way
> to distinguish them without renaming them.

If you make ten copies of a template, you need to distinguish each of the
ten somehow.  Since you'd rather not rename them "copy1" through "copy10"
you can identify each copy in a custom property set of the object that
contains them.

<script>
function copyTemplate pTemplateName,pLibraryName,pTarget
  put the uTemplateCopies of pTarget into tTemplateCopies
  put the keys of tTemplateCopies into tKeys
  filter tKeys with pTemplateName,pLibraryName,"*"
  put number of lines in tKeys + 1 into tCopyNumber
  copy group pTemplateName of stack pLibraryName to pTarget
  set the uTemplate of it to pTemplateName,pLibraryName
  set the uCopies of group pTemplateName of stack pLibraryName to \
    the long id of it
  set the uTemplateCopies of pTarget to tTemplateCopies \
    & pTemplateName,pLibraryName,tCopyNumber & cr
  return tCopyNumber
end copyTemplate
</script>

Then each template knows its copies, each copy knows its template, and each
target knows which copies of which templates it contains. Your code can
refer to a control in any of the copies using an "of group id" clause to
disambiguate the altIDs.

<script>
  put the text of control id tAltID of group id \
    the uTemplateCopies[tTemplateName,tLibraryName,tCopyNumber] of tTarget
</script>

Please note that the above code is a suggestion typed into an email, rather
than tested code copied from a working app.  Does the suggestion work for
you?  If you improve the code somehow, please share your results.

-- Dick





More information about the use-livecode mailing list