How, in an expression, do I use a variable in the name of an array ?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello

    In my game I'm using multiple arrays and I want to have them all processed with a single function.

    Here's hat I have for example :

    I have to process arrays named :

    - SubsArrayfr

    - SubsArrayBzh

    - SubsarrayEn

    In the expression, is there a way to replace "SubsArrayFr" by something like "SubsArray"&Variable, where Variable can be Fr, Bzh or En ?

    Tagged:

  • Nope, you pass through a parameter which triggers the 'for' loop you want to use. So pass through 'fr' and then say if param=fr run that loop, if param=en run different loop.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Another option is to add all these array into a family. Then you could pick family instance by name, using this condition:

    System Pick ArrayFamily by evaluate: ArrayFamily.ObjectTypeName=nameVar

    .

    You can also use a single array object with several instances - just like you do with sprites. Each instance will store strings for one language. Define an instance variable "lang" on the array and pick array instance by variable value.

  • Another option is to add all these array into a family. Then you could pick family instance by name, using this condition:

    System Pick ArrayFamily by evaluate: ArrayFamily.ObjectTypeName=nameVar

    .

    You can also use a single array object with several instances - just like you do with sprites. Each instance will store strings for one language. Define an instance variable "lang" on the array and pick array instance by variable value.

    Hello dop2000,

    Actually, I'm updating your video subtitles template and try two approches :

    - use one and unique array and add to it a line for each different language.

    - use a array for each language

    I choosed the second one.

    It works perfectly, but I'm sure the way I did it is absolutly not optimised : I didn't manage to create just one SubtitleParse function and had to duplicate it 3 times for each of my 3 langages. I did the same for the Show Subtitles routine. For example in the following screencap, is the parse routine for French Language. With the red line in front, Arrays I would like to be able to pick for each language.

    My solution works, even if it is not optimized. I'll at yours :) it's a great lesson. Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)