Complex arrays

0 favourites
From the Asset Store
Array Editor
$1 USD
80% off
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I think this may require a plugin, I need to handle a VERY large arrays from where I'll select values at randomly.

    The array would be structured like this:

    var group1= [ 'zero', 'one', 'two', 'three', 'four', 'five', ... ];

    array['group1'] = group1;

    This repeated for a lot of times.

    Then I need to do this:

    Select array['groupX'][Math.floor(Math.random() * array['groupX'].length)]

    For each of the "main" indexes.

    Is this possible to do with construct2?

    I presume I need to write a plugin since inputting this much data in c2 would be an endless job.

    How do you create an array plugin like this?

    Thanks

  • I don't know the answer on how to do this, but may I ask 'why' this is needed?

    Is there another way to approach the problem that is less memory intensive?

  • Arrays are not memory intensive at all, and there are no other ways to do what I want, it's an educational application, basically I procedurally generate questions from questions and answers arrays and then load the corresponding graphics. It's an easy task and I'm evaluating if doing it on c2 or a "normal" javascript engine.

  • You should have a look at the system expression(Text section) tokenat, it sounds like it is exactly what you would need.

    Search it as a keyword, there should be topics available that give examples of use.

  • Global Text groupList = ""
    + System: on start of layout
      -> set Text groupList to : "zero,one,two,three,four,five
    zero,one,two,three,four,five
    zero,one,two,three,four,five
    zero,one,two,three,four,five
    zero,one,two,three,four,five
    ..."

    Each line is a group with its values.

    And then if you want to pick a random value from let say, group 3

    + On what you want
      Local Text group = ""
      -> System: Set group to tokenat(groupList,3,newline)
      -> Text: set text to tokenat(group,floor(random(tokenCount(group,","))),",")

    Works like a charm.

  • You can create as many of the Array object as you like at runtime, as well as access them using pick nth, and array(index).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yann I see thanks.

    Other question, is it possible to pick an object with its name. Like I have

    global text var sprite = "mysprite"

    system create object sprite at x 10 y 10

    ?

  • nope 'cause 'mySprite' isn't the name of an object, but the name of an objectType. The object you have on your canvas are instances from this objectType.

    There's two ways to refer to a specific instance:

    • picking
    • using IID in expression

    To pick you have to isolate an object via a condition.

    It could be for example

    - mouse: is overlapping this object

    - object: pick by Unique ID

    - System: pick nth instance of an objectType

    - object: myVar = something

    - ...

    Any condition for which the specific instance will be true will initiate the picking of this specific instance, and then you'll be able to use it and only it in an action

    The other one is using IID in expression. Each instance of an objectType has an Instance ID.

    (Not the same as UID, Unique ID is a Unique number identifying all objects present in your layout, whereas IID are assigned by objectType)

    Then via this IID you can do something like

    System: Every Tick :
      -> Sprite: Set angle to angle(self.X,self.Y,Sprite((self.IID+1)%Sprite.Count).X,Sprite((self.IID+1)%Sprite.Count).Y)

    Basically each Sprite will angle toward the next in the IID list. (I used that in cubemaze to draw the ellipse in the menu)

  • Is it possible then to set the unique ID to something arbitrary?

  • nope Unique ID and Instance ID are automatically assigned on creation

    By setting a unique ID arbitrary you would have risked it to not be unique anymore...

  • Is it possible then to set the unique ID to something arbitrary?You can make an equivalent of an arbitrary unique ID by assigning a custom value or string to an instance variable. Then you can pick the instance by comparing the instance variable. It works the same as picking by UID. Just be aware that if there's more than one instance with that same value they will be picked as well.

  • Animmaniac Are you sure you can?

    I created a instance variable on my object (Which is always one) but I can't find any event that picks it! There is pick all pick nth intance.. but not pick by instance variable.. Can you explain a little better?

  • The question you have to ask yourself is why you want to pick a specific instance instead of another. By answering this question you'll find how to pick it.

    For example if you want to pick a specific instance because it's underneath the cursor

    +Mouse: is over Sprite
      -> Sprite: set myCustomID to 1
  • 0plus1: Compare instance variable

    Then due to how events work, only the instances with the value you are comparing gets picked/filtered.

    Also be sure to check the section "Picking/selecting" in the how do I FAQ, all this has already been treated in several topics.

  • 0plus1 you use a "Compare instance variable" condition for picking. I think you need to understand better how picking works, every event that reference an object is picking, not just the conditions that start with "Pick".

    You can get more information here:

    http://www.scirra.com/manual/75/how-events-work

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