Creating variables

François Chaplais francois.chaplais at mines-paristech.fr
Wed Aug 6 09:41:08 EDT 2008


Le 6 août 08 à 14:26, Eric Chatonet a écrit :

> I'm sorry, I was a bit quick: all this works when getting/setting  
> properties only:
>
> put the long ID of fld "MyField" into tObj
> set the text of tObj to empty
>
>

I think I have found a workaround for working with "variables"  
referenced by names. It involves custom property sets. These can be  
referenced by name. Here is an button script example:

on mouseUp
   ask "Custom property set?" with "example"
   if it is empty then
     exit mouseup
   end if
   put it into theName
   set the customPropertySet of me to theName
   put the customproperties[thename] of me into myProps
   --  creation of variable by asking name; can be replaced by  
anything that returns a string
   ask "Name of pseudo variable:" with "anExample"
   put it into varName
   if varName is empty then
     exit mouseup
   end if
   -- assigning value of "variable" anything will do, I think, since  
this is a custom property
   ask "value of variable" && varName -- put your code here
   if it is empty then
     exit mouseup
   end if
   put it into myProps[varName]
   set customproperties[thename] of me to myProps -- value is set
   answer "Do you want to retrieve the value of your variable?" with  
"Cancel" or "OK"
   if it is "OK" then -- retrieve variable value
     put the customproperties[thename] of me into myProps
     get myProps[varName]
     answer "This is the value of variable" && varName & ":" && it
   end if
end mouseUp

I think this can be made pretty generic and split into several  
independent handlers/functions. Moreover the variables can be  
accessed globally and are stored in the stack file upon save. haven't  
tried in in a standalone for the moment, though.

Best regards,
François



More information about the use-livecode mailing list