How do I access Array actions via a string?

0 favourites
  • 8 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Hi! Is it possible to use a variable instead of the array object name somehow?

    I made a function to show data (loop to create text objects) and added a parameter but it seems there is no way to use the parameter in the array actions. I added x sub events with compare param = xxx and then copied to actions to each subevent. Now I have to change all sub events when I make adjustments. It would be much easier if you could replace the fixed array.At() with a string.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure I fully understand your question.. You can add all arrays to a family, add an instance variable Type, set it for each array object. For example one array will have Type="buildings", another Type="resources" etc.

    And use it like this:

    Function ArraySetValue
    parameter t
    parameter i
    parameter v
    	ArraysFamily compare variable Type=t
    		ArraysFamily set at X=i, value=v
    
    
    // Usage: 
    	Call function ArraySetValue (t="buildings", i=23, v=2000)
    	Call function ArraySetValue (t="resources", i=0, v=1.5)
    
    
  • another thing you can do is use a dictionary. I read a lot of data from an Database. I can send a query to the database, and it returns a list of the field names, and then all the matching records. the field names get loaded into a dictionary called "Fields", and the records get loaded into an array.

    then I can access the data like:

    array.at(RecordNumber, Fields.Get("FirstName"))

    if I change the query, and the FirstName field ends up in a different position in the array, the dictionary automatically takes care of that when it gets loaded - so I don't have to update any code.

    And, like dop said, if you have multiple array objects, you can can put them in a family, and pass the UID of the array object you are interested into a function, and pick that by UID inside the function.

  • Thanks for your replies!

    Only used families to spawn a random enemy and did not remember you can use them for actions.

    I added a family instance var and set the 2 array IDs to BL3 and BL2.

    I tried this and it seems to work fine. :)

    + System: On start of layout

    -> Array: Set value at 0 to "BL3"

    -> Array2: Set value at 0 to "BL2"

    ----+ System: Pick Family1 by evaluating Family1.ID="BL2"

    -----> Text: Set text to Family1.At(0)

    When I change the pick ID it shows a different value.

  • Actually, you don't need a family. Arrays can also have multiple instance. So you can create 5 instances of Array object and store different data in them. Pick any instance of Array with an instance variable.

  • How do you create instances of arrays? Ctrl+drag works for sprites and other objects, but arrays are no object in the editor. With System Create object?

    dop2000

  • you do it in the event sheet - System Create Object ArrayName

    you can also add an array to a container. Then, whenever an instance of the container is created the array will also get created (and automatically picked with the container).

  • Thanks! I'll try it. 👍

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