How do I create a 900 block grid?

Get help using Construct 2

Post » Wed Sep 28, 2016 8:42 pm

Probably biting off more than I can chew for my second game, but there might be an easier way to do this than to create 900 sprites that are clickable and changeable.

I have a 29x31 grid I want to be able to click each square and change it to a different object. It will be like a tower defense game.

My fears:
... to do 900 sprite objects all by hand
... do it in an un-optimized manner where the game won't run properly
... run into a dead end and have to start from scratch.

Any helpful suggestions, words of wisdom, or places to start would be greatly appreciated.
B
7
S
2
Posts: 28
Reputation: 483

Post » Wed Sep 28, 2016 8:49 pm

on START LAYOUT
FOR 1 TO 900
SYSTEM CREATE "!"
B
15
S
7
G
7
Posts: 201
Reputation: 5,277

Post » Wed Sep 28, 2016 9:23 pm

I don't use skype anymore, I use discord. Unfortunately, I can't send you a pm, I'm too new.
B
7
S
2
Posts: 28
Reputation: 483

Post » Wed Sep 28, 2016 10:50 pm

The for loop are amazing. Id would do something thing like during an onstart and duriing a loading screen and do if loopindex = 900 start the game so that it loads it all without player input screwing. Up
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Wed Sep 28, 2016 11:01 pm

As you described, the solution is to use nested loops and loopindex - For "x" from 1 to 29, then For "y" from 1 to 31 as a sub event. Your action would be to create a tile object at x, y where x is loopindex("x")*gridwidth and y is loopindex("y")*gridheight. You can add a constant value to each of these to offset the start position.

In terms of optimization though... I personally would not create a potentially unused object for all the empty spaces and only create them when needed, in the right place.

General words of wisdom - Never fear running into a dead end. In the process of doing so, you will learn exactly why and how a dead end can occur, and how to work around it. Also, there is no such thing as starting from scratch, as long as you have the experience of going through whatever you did previously. A program that takes you a month to write the first time, even if you were to lose everything, you could probably recreate in just a few days the second time you do so.
Mistakes were made.
B
48
S
23
G
107
Posts: 1,576
Reputation: 60,168

Post » Thu Sep 29, 2016 11:53 pm

OK, I did it, but I can't click one to change it.

Is it not
on touched (sprite) - system create object (a different sprite) at (first sprite.X, first sprite.Y)
- first sprite - destroy
?

I know it works, but it doesn't work with sprites created with the loop.


my game file is here: www -dot- cazualnoob -dot- com/web-games/
B
7
S
2
Posts: 28
Reputation: 483

Post » Fri Sep 30, 2016 1:41 am

You forgot to add on start of layout on you non-disabled grid generation event. Your grid is being created every tick, which immediately covers up your single "dirt" tile you place.
Mistakes were made.
B
48
S
23
G
107
Posts: 1,576
Reputation: 60,168

Post » Sat Oct 01, 2016 1:37 am

Well, that worked like a charm and I did it.

I've been searching all day and trying to find a way to select or pick a specific sprite without interacting with it with a touch or anything. Like, I want to indirectly affect a tile. I want a character to chop down a tree that is close to him. Do I have to click on the tree and say cut down, then he'll walk over and cut it down, or can I just put him somewhere and say cut down the nearest trees in reach?

Is the loop not an array or can I mark each sprite block with an instance variable id? Construct 2 is so different than what I'm used to - scripting.

It's so frustrating when I can't figure out something that I think would be so easy.

I uploaded the newest game file to my server.
B
7
S
2
Posts: 28
Reputation: 483

Post » Sat Oct 01, 2016 2:27 am

You can mark each sprite block with an instance variable. When an object is created, it is "picked" automatically for the duration of that (sub)event. So if you create an object, and set an instance variable, it will only set it for the instance that was just created.

You can use conditions such as Pick sprite by instance variable to pick "trees", then use pick nearest sprite to get the nearest tree.
Mistakes were made.
B
48
S
23
G
107
Posts: 1,576
Reputation: 60,168

Post » Sat Oct 01, 2016 1:24 pm

I'm surprised and thankful you're still answering my silly questions. I'm slowly chipping away at this mountain and thank you for your patients.

I've changed the creation of the sprite grid to include random(), but the 10 ways I tried don't seem to work even though it accepts it and it's completely logical. But that's not even my real problem.

Don't bother looking at the gate commands, I haven't gotten around to that yet.

I got the id's to work like a charm - I think...
I had them kind of working better earlier, but they weren't getting there, so I tried a different approach. I think I'm closer, but I don't think my new way is going anywhere either.

I can honestly say I have no idea what is happening with the random generator or the grid sprite swapping.

my game file is here: www -dot- cazualnoob -dot- com/web-games/
B
7
S
2
Posts: 28
Reputation: 483

Next

Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest