Stupid Arrays!!!

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I understand arrays. I understand loops. I understand FOR statements

    I do not understand how to implement it in C2!!!

    What I have is this.

    Array varAvailTowers ( 2, 20 ) { 2 rows of 10 } 0 - 1, 0 - 9

    At the beginning of a level I want to loop through the varAvailTowers and fill a box on the screen with the appropriate power-up / tower.

    So...

    On Beginning of Layout

    For ROW = 0 - 9

         For COL = 0 - 9

              TowerForSlot = varAvailTowers.at(ROW,COL)

              CreateObject "TOWERFORSLOT" at (SCREEN COORDINATE FORMULA)

    Does that make sense?

    I will probably store the SCREEN COORDINATES in another array and grab the coordinates from that based on the ROW, COL....

    Help!!!

  • First, you can't refere to an object by the name of its object type in a create action. So CreateObject varAvailabTowers.at(ROW,COL) at (X,Y) isn't really possible like that.

    However there's a work around: put all your different tower in different animation frame of the same object, and store this data in your array.

    I don't have enough information to really grasp what you want to do, but it looks like you have a map in your array that holds the position of some towers.

    So basically the creation process should look like:

    Global number gridX = 0  // X position of top left corner of the map
    Global number gridY = 0 // Y position of top left corner of the map
    Global number cs=32  // grid cell size
    Global number cols = 10 // number of columns of the map
    Global number rows = 10 // number of rows of the map
    + On Start of layout
    + For "y" from 0 to rows-1
    + For "x" from 0 to cols-1
      -> Create mapObject at (gridX + loopindex("x")*cs , gridY + loopindex("y")*cs)
      -> mapObject: set animation frame to map.At(loopindex("x"),loopindex("y"))

    If your mapObjects have some animation, you should suffix the animation name with an ID and use a private variable to identify the object.

    The last line would be changed to

      -> mapObject: set objID to map.At(loopindex("x"),loopindex("y"))

    Then you will just have to always play your animation like that:

     -> mapObject: set animation to "Attack_"&mapObject.objID

    With this technique you can not only place towers but any object you want to set (trees, bushes, rocks, etc) The only downside is that you can only have one object per cell (unless you use a 3D array for layering)

    That's all

  • Here is what I am trying to do...

    The HUD locations where the LITTLE towers are is the location that I am trying to fill with either a TOWER or a LOCK if it is not available.

    docs.google.com/open

  • Your HUD is weird, why is you hudTowerSelectBoxes a pair of square?

    Explain a little more of what you want, a schematic can help.

    Also don't create another topic about the same subject, you'll make things harder since you'll have to explain your problem again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey SparkDad. I can't download that file without signing up for Google Drive. I don't suppose you could upload it somewhere else?

  • I will post a screen shot a little later. The HUD is just a test template that will change a lot. I just needed some area to put the towers : )

    I think I have a working piece of code that I will put up later tonight.

    Thanks!

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