My ongoing problem.

Get help using Construct 2

Post » Wed Jan 29, 2014 5:28 am

Hi again, this is my prototype match 3 game that uses 00Rez's Astar pathfinder plugin.



I'm having trouble moving each of the 3 colors new instances separately. I would like to click on a red, green or blue sprite and have it move to a blank spot on which I've clicked on without all of it's other instances moving to the same spot. I don't think using UID would be efficient here because I would probably need to create another event for each one that spawns correct??? That would be unmanageable with 1 new colored instance being spawned after each mouse click.

Here's a look at my event sheet. With it set up the way it is I can only move the first instance of each of the 3 colors...





Please help me out with this, and tell me what I'm doing wrong. Thanks sooo much in advance!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Wed Jan 29, 2014 7:13 pm

when you click on the block, copy it's UID to a variable (SelectedBlock). When you click on an empty block copy it's UID to a variable (EmptyBlock). After your click move SelectedBLock to EmptyBlock. Or you could just capture their X,Y coordinates. So On click empty block store the X,Y in the emptyBlock variable, and on click the SelectedBlock copy it's X,Y. to the SelectedBlock variable. Then just set selecteblocks X,Y to the coordinates stored in emptyBlock.
You would also need to check if you can move to that square though.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Thu Jan 30, 2014 5:01 am

@BluePhaze Hi BluePhaze thanks for responding. I'm not fully understanding how to utilize your method in this kind of game. Do I need to create a variable for each of the sprites instances? If so that would be hundreds maybe even thousands possibly depending on how long the player lasts in the game. There has to be a far more efficient way to just pick the sprite instance you click on and have him move independently. Also my sprites move in a grid based pathfinder way square by square so you see them traverse a path, not just click and appear.

I'm sorry if I'm seeming a little negative, it's just that I've been trying to fix this for weeks now. It seems like a simple concept and it probably is I just can't figure it. I'm attaching my .capx and the pathfinder plugin I use. Please BluePhaze or anyone else that happens to see this please play what I have so far. It's not set up for matching yet, I'm just trying to get all the sprites and their instances individual movement down first. Thanks again for your help and patience.

Here are my files: My .capx and Pathfinding plugin
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Thu Jan 30, 2014 5:07 pm

The variable is an instance variable, you create it once on the sprite and all instances would instantly have it. You just set it to the current X,Y coordinates of the instance. You could do this with one for each loop, for each object A > Set objectA.Variable to objectA.X, ObjectA.Y

Something like that would do all of them at once. Then when you click, you just read that variable from the sprite you clicked on.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Fri Jan 31, 2014 12:19 am

@BluePhaze Hey BluePhaze, thanks for responding again I really appreciate it. I have a question, is there a particular format that I need to adhere to as far as storing the X,Y of the sprite in an instance variable? How would I word it because it's not like expressions in the events where it won't let you enter it if it's not in the right syntax format. Please let me know, and thanks again!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Fri Jan 31, 2014 5:42 am

@33miles Store it as 2 variables, one for the X and one for the Y. Then you can set the X and Y of the block using the two variables.
Block.X = VariableA
BLock.Y = VariableB
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Fri Jan 31, 2014 7:34 am

@BluePhaze Sorry to keep troubling you BluePhaze but I'm still not getting it. I set the instance variables like this:



And the event like this:



But now it moves all of them at the same time. If you could further clarify this I would really be thankful! I'm so sorry I don't mean to be dumb but if you could just make the way the event should go and syntax a bit more ABC I could comprehend better. If I get over this big hump I could go on with my game. Thanks for your patience and help!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Fri Jan 31, 2014 10:41 pm

@33miles Your for each statements are causing an issue I believe. You are basically saying, if I click on a read block and it's ready, then loop through all the others and move them.

For each should be the first item in a condition most of the time, or in a subcondition.BluePhaze2014-01-31 22:42:33
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Sat Feb 01, 2014 1:43 am

@BluePhaze Thanks for the advice BluePhaze, I changed the event which now looks like this:



But now things are kind of weird, I still can't move the red instances individually. And when there are multiple red instances on the board and I try to move one they all move to the same spot but some teleport. Please look at my updated .capx and see if you can find out what went wrong. Thanks so very much I really appreciate all your effort BluePhaze!

Here's the updated .capx And the Pathfinder Plugin I use. Thanks again!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Sat Feb 01, 2014 8:20 am

Ok a few questions:

Why are you checking if redblocksready is bigger or equal to 1 when all you have got is an event to set it to 1?
Why is readblocksready a global variable and not an instance variable?
In what way are you telling the program which of the red blocks you want to act?
Why are you using a third party plugin for pathfinding when C2 has a built in one?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: lahbach and 25 guests