Beginners global variable pb

Jeanne A. E. DeVoto revolution at jaedworks.com
Thu Feb 19 16:35:51 EST 2004


At 6:33 PM +0100 2/19/2004, Benoit Leraillez wrote:
>- The first card let's the user select the language interface for the rest
>   of the stack. I know how to change on the fly the texts on that card to
>   the user's selection from the scrolling list field. But I haven't found
>   a way to store that selection so that every text field on every card
>   displays text in the correct language (LanguageChoice is a global variable
>   defined in the stack script in open stack and modified in the language
>   selection script).
>
>   Since I defined the variable as global up in the stack I don't understand
>why it doesn't apply to every card and field. Maybe there is another way to
>do this?

Are you declaring the global variable wherever you need to use it? (A 
global needs to be declared in each handler where you access its 
value.) For example, if you store the language in a mouseUp handler 
in a button script, you can use the language anywhere - but you must 
declare the global:

   on openCard
     global languageChoice -- now it is accessible
     answer "The language is" && languageChoice
     -- shows previously-chosen language choice
   end openCard

>   (On top of that the ideal for me would be to have a hidden card containing
>a table where each column would be a language and each row a field's content
>since I could then keep simpler code in the text fields and probably import
>and export the translations to work on it elsewhere than in Revolution.

You might want to put the translation for each language into a custom 
property instead. (Take a look in the docs, in the topic "About 
custom properties and custom property sets", which you can find under 
"Values and Properties" when viewing all documentation by category. 
About halfway down there is a short translation example for exactly 
this situation.)

The basic idea here is that, instead of having a hidden card, you 
have sets of custom properties for each card - one set for each 
language - to hold the correct text for that card.

For example, suppose you have two fields - Title and Main. To store 
the French translation, you would create a custom property set named 
"French", and in that set, there would be two properties - one for 
the Title text, and one for the Main text. Similarly, for each other 
language, you would create a custom property set that contains two 
properties - so you could have sets named "English", "Spanish", etc.

Then in a preOpenCard handler, you find the correct set for the 
current language, and put the text for that language into the two 
fields. Here is a quick example:

   on preOpenCard -- this handler goes in the stack script
     global languageChoice
     set the customPropertySet of this card to languageChoice -- switch sets
     -- this lets you access the custom properties in that set
     -- because the customPropertySet has been set to the language, the
     -- next two lines get the custom properties from that set.
     put the titleText of this card into field "Title"
     put the mainText of this card into field "Main"
     set the customPropertySet of this card to empty -- back to default set
   end preOpenCard

(I hope this isn't too confusing. Some of these ideas - custom 
properties, custom property sets - may be new to you since you're a 
beginner. If you prefer you can ignore all this for now, and just 
keep it in mind for later. ;-)


>P.S. Oh! Just one more thing, is there a way to have an image put in such
>away that it appears in every cards at the same place when you create a new
>card? And if you modify that image you don't have to copy and paste hundreds
>of times? It ain't a priority but it would be cool ;-)

Certainly! To do this, you make the image into a shared group. 
(Groups usually contain more than one object, but you can create a 
group with one object too. This is useful when you want to share a 
single object among different cards, because groups can be shared in 
this way.)

First create the image, then select it with the pointer tool and 
choose "Group Selected" from the Object menu. This makes the image 
into a group.

If you want the group to appear automatically on all the new cards 
you create, set the group's backgroundBehavior property to true. You 
can either do this in the message box, or check the "Behave like a 
background" box in the group's property inspector window.
-- 
jeanne a. e. devoto ~ jaed at jaedworks.com
http://www.jaedworks.com


More information about the use-livecode mailing list