importing a bunch of files

Richard Gaskin ambassador at fourthworld.com
Wed Jan 16 16:13:30 EST 2008


Randall Lee Reetz wrote:
> In your script, it appears that a custom prop is dynamically declared  
> just by setting it's value?  Is this all you have to do?  In  
> SuperCard, one has to specifically declare a "user" property with a  
> "define" statement before ever setting it's value.

Yeah, and that extra line needed to declare every custom property used 
to drive me crazy.  I submitted a request to change that back when Gary 
Poppitz was SC's lead engineer, but he felt strongly about it so it 
never happened.  I was sure tickled to find it in Rev.

Gary's thinking was that he wanted to avoid having requests for props 
that didn't exist, but in practice that's rarer than assigning them so 
the tradeoff doesn't buy you any additional productivity.

When you try to access a property that doesn't exist in Rev, it just 
returns empty.  So how do you know whether it's not there or perhaps 
there but merely empty?  In such cases you can query the customKeys 
property:

   get the customKeys of btn 1

This returns a return-delimited list of all custom props in the current 
property set.   Keep in mind that you can have any number of property 
sets in an object, and switch between then with:

   set the customPropertySet of btn 1 to "UserData"

This can be especially handy when you have lots of different data for 
which it would be useful to use a single key.

For example, if you had some info about users you could do this:

   put "bob" into tName
   put "Age,Rank,Serial" into tSets
   repeat for each item tPropSet in tSets
      set the customPropertSet to tPropSet
      put the tName of this stack into fld tName
   end repeat

Lots of tricky things can be done with property arrays.


Now kindly allow me to blow your mind:

How many times have you wanted to replicate an object, but using copy 
and paste seemed cumbersome and you didn't want to muck with the user's 
clipboard?

In Rev, you can use "copy...to...", e.g.:

   copy btn 1 of stack "templates" to this cd

This copies the object into the current stack, and using the "to" form 
of "copy" leaves the clipboard alone.

But it gets better:

Just as you can get all of the customKeys of an object's property set as 
I noted above, you can even get all of the modifiable built-in 
properties as well, returned to you in a convenient array - try this, 
which also combines the array elements into a list for easy viewing:

     put the properties of this stack into tmp
     combine tmp with cr and tab
     put tmp

So you can get and set all modifiable properties in a single line.

But if that's not convenient enough, you can also transfer all built-in 
properties from any object to any other of the same type in one line:

   set the properties of btn 1 to the properties of btn 2


Let's take this one step further:

Suppose you needed to create a hundred graphics on the fly, each with 
specific properties.  You could create them and then assign their 
properties, but Rev also gives us template objects, virtual objects from 
which anything created with the "Create" command will adopt all their 
properties.

So you could make those graphics like this:

    --  Just set up the template object...
    set the properties of the templateGraphic to \
      the properties of grc "MyTemplate"
    --
    -- ...and create the objects as normal:
    repeat with i = 1 to 100
       create grc
    end repeat


Ah, the limitless possibilities....

:)


Rev's associative arrays and property sets are so useful that I 
recommend everyone take at least half a day just to play with them. 
Once you get a good feel for them a great many solutions become quick 
and easy, and often fun.

-- 
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list