Stupid Arrays!!!

Get help using Construct 2

Post » Wed Jul 11, 2012 5:05 am

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!!!
B
12
S
1
G
1
Posts: 50
Reputation: 1,228

Post » Wed Jul 11, 2012 7:08 am

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:
[code]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"))[/code]

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
[code] -> mapObject: set objID to map.At(loopindex("x"),loopindex("y"))[/code]
Then you will just have to always play your animation like that:
[code] -> mapObject: set animation to "Attack_"&mapObject.objID[/code]

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 allYann2012-07-11 07:11:06
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jul 11, 2012 4:53 pm

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.

https://docs.google.com/open?id=0B5puA55FudSeQjJRU285LUlobEk

B
12
S
1
G
1
Posts: 50
Reputation: 1,228

Post » Thu Jul 12, 2012 3:41 am

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.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Jul 12, 2012 3:56 am

Hey SparkDad. I can't download that file without signing up for Google Drive. I don't suppose you could upload it somewhere else?
B
55
S
12
G
8
Posts: 339
Reputation: 9,314

Post » Thu Jul 12, 2012 4:29 am

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!
B
12
S
1
G
1
Posts: 50
Reputation: 1,228


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests