Can we pass global variable value into the instance variable by breaking the instance variable?

0 favourites
  • 5 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Just wondering how to accomplish

    I have several instance of the same gAMEoBJECT (sprite) and have instant variable like "IVnumber_1", "IVnumber_2", "IVnumber_3" etc.

    Can we pass global variable value into the instance variable by breaking the instance variable

    like (#1) πŸ‘‰ gAMEoBJECT.IVnumber_&GlobalVariable πŸ‘ˆ

    also tried like this (#2) πŸ‘‰ "gAMEoBJECT.IVnumber_"&GlobalVariable πŸ‘ˆ

    but neither of this working, pleas help.

    *Having said that the Global Variable which I talking about will pass the integer value to the instance variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If there is mix between number & string you will likely end up convert them into string. Do you store string or number on instance variable? Assume that instance variables numbering is what you are after;

    -straight expression would be: gAMEoBJECT.IVnumber_1 for example

    -You probably expect gAMEoBJECT."IVnumber_"&GlobalVariable

    to work but no it's not work that way.

    But if it just a string you could retrieve it's ObjecTypeName and put global variable value:

    + System: On start of layout

    -> System: Set GlobalVariable to choose(1,2,3)

    -> Text: Set text to gAMEoBJECT.ObjectTypeName&"."&"IVnumber_"&GlobalVariable

    That will display "gAMEoBJECT.IVnumber_1" or "gAMEoBJECT.IVnumber_2" or "gAMEoBJECT.IVnumber_3"

  • Hi alextro,

    this one looks interesting

    -> Text: Set text to gAMEoBJECT.ObjectTypeName&"."&"IVnumber_"&GlobalVariable

    but still

    it still passing it as a string, like this one

    also tried like this (#2) πŸ‘‰ "gAMEoBJECT.IVnumber_"&GlobalVariable

    but anyways thanks for your response :)

  • Is there any specific reason why you need to doing so? I believe there is more effective way to deliver certain task done.

  • You could abuse an array for that.

    First x can be the combination of name and numbers etc, making it a string. Second value can be whatever value you stuffed in there.

    Then you can fetch the second value corresponding to the combined variable name with a loop or some fancy search, and use the results in any object or variable you desire.

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