How to store a stack in a custom property

J. Landman Gay jacque at hyperactivesw.com
Mon Apr 27 16:16:35 EDT 2009


Joe Lewis Wilkins wrote:
> For example: say you have a whole bunch of cards and there is an image 
> that will be displayed on each card; can you set the customproperty of 
> each card to an image? I'm assuming that each object in a stack may have 
> only one customproperty and that assumption may be wrong, so????

There are no limits to the number of custom properties an object can 
have outside of normal memory and disk space restrictions. So yes, you 
can easily store one image per card in a custom property. Or you could 
store several in different custom properties, and display whichever one 
is appropriate for the current context. Note that for images, where 
you'll always have the same one per card, it's easier to just place the 
image normally. But if you need to switch the image content dynamically, 
then loading the property into an image object on preOpenCard is one way 
to do it.

I use the technique you mention a lot. For example, you can't set an 
option button in a shared background to display differently on each 
card, it will always show whatever menu item was last selected. To fix 
that, store a custom property for the choice that should be displayed on 
that card. I.e., say you have a stack that stores book titles, one per 
card, and you want to rate each book after you've read it. You rate it 
from an option list of pre-defined choices ("Great","So-so","Waste of 
time".) When you view each card you want the option menu to display the 
correct rating, so to keep it straight, store the rating for each book 
as a custom property of its card:

  on menupick which -- in the option button
    set the rating of this cd to the menuhistory of me
  end menupick

Then on preOpenCard, set the option menu to the custom property you stored:

  set the menuhistory of btn "rating" to the rating of this cd

The option menu will now change dynamically as you page through the stack.

To take it further, you can divide an object's custom properties into 
logical sets if you want and only use the appropriate set at any given 
time. Each set can have duplicates of the same custom properties, though 
each property may contain a different value in eash set. This is often 
used for language translation, for example. You can have a property set 
for English, another for Spanish, another for French, etc. Within each 
set are the same-named custom properties for perhaps different types of 
words: greeting, goodbye, etc. Then you load the correct set before 
using the custom properties, and your scripts will display the correct 
language automatically:

   set the customPropertySet of this cd to "french"
   put the thankyou of this cd -- "merci"

   set the customPropertySet of this cd to "english"
   put the thankyou of this cd -- "thanks dude"

If you get that far, there's more info in the dictionary. There's a 
shorter way to refer to the properties inside sets by using array 
notation, but I think the above method is easier when first learning 
this stuff.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the Use-livecode mailing list