How do I display what tile ID I'm currently clicking on?

Get help using Construct 2

Post » Sun Mar 19, 2017 4:21 pm

So I'm making a sort of sandbox crafting game along the lines of Terraria and Starbound. I have a tilemap that has the blocks that I'm making the world out of. I currently have grass and dirt. What I would like to happen in the game, is when I click on grass, it adds a value to a global variable: "grass," and when I click on dirt, it adds a value to a global variable: "dirt." And when I place grass, it subtracts 1 from the "grass" variable, and same with dirt. The problem is, no matter what tile I click, it adds 1 to the variables I currently have set up, which are grass and dirt. I'm also confused because even if I click on nothing, as long as it's within the tilemap's borders, it'll still add 1 to the grass and dirt variables. In the current game, I have in the event sheet, when the tilemap itself is clicked on, it adds to the grass variable. I know that's causing the problem; I just don't know how to add another condition that triggers the event when only grass is clicked on, or only dirt is clicked on.

Basically, to sum it up, I'm looking for a way to have the game add to only the grass variable when I click on grass. Same with other blocks and their variables once I add them. I'm totally new to Construct 2, so I might not understand anything complex :lol:
B
5
S
2
G
1
Posts: 3
Reputation: 931

Post » Sun Mar 19, 2017 5:57 pm

Use the expression
Code: Select all
[Tilemap].TileAt(PositionToTileX(Mouse.X),PositionToTileY(Mouse.Y))

when clicked, to retrieve the Tile ID at the current mouse position.

You can then compare the Tile ID that was returned by the expression with the Tile ID of, e.g., grass and add to grass if the comparison is true.

If you need further information/help, give me a shout.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Mar 19, 2017 6:14 pm

Using a globals as requested.

https://www.dropbox.com/s/07fus6w961l81 ... .capx?dl=0

But, as you see, you need an event for each global. The event sheet will get way to long. And at one point you get lost in all those events. Why not use a dictionary ?

https://www.dropbox.com/s/zfbkqdzuvoj5q ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Mar 19, 2017 8:14 pm

Message: ScrubStorm can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I used globals, and it worked very nicely! Thanks to the both of you. Just as a little extra question: I set up a way to build with certain blocks, grass and dirt. Every time I place grass, it subtracts 1 from the grass variable, and same with the dirt block and it's variable. The problem I'm having is that I can spam a block on the same tile, and the variable keeps subtracting. Is there any way to make sure that if I'm placing a block, I can't place it on another one?
Here's a link to my video: https://www.youtube.com/watch?v=exYZU0o ... e=youtu.be
B
5
S
2
G
1
Posts: 3
Reputation: 931

Post » Tue Mar 21, 2017 10:39 pm

Can't view your video since the URL has been shortened.
But I'm pretty sure, that this would solve your problem:
Check whether (when clicked), this expression
Code: Select all
[Tilemap].TileAt(PositionToTileX(Mouse.X),PositionToTileY(Mouse.Y))

returns -1.
If it does, that means that the currently clicked tile is empty, meaning that there is no tile at the moment.
If the expression returns anything else but -1, there is a tile already.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Thu Mar 23, 2017 12:02 am

Thanks! I appreciate it.
B
5
S
2
G
1
Posts: 3
Reputation: 931


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests