My ongoing problem.

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

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/HelpMePick1_zps524ceaa0.png" border="0" />

    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...

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/HelpMePick3_zps68d2c23b.png" border="0" />

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/HelpMePick4_zps7e5414f6.png" border="0" />

    Please help me out with this, and tell me what I'm doing wrong. Thanks sooo much in advance! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • 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.

  • 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. <img src="smileys/smiley1.gif" border="0" align="middle">

    Here are my files: My .capx and Pathfinding plugin

  • 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.

  • 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!

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • BluePhaze Sorry to keep troubling you BluePhaze but I'm still not getting it. I set the instance variables like this:

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/RedInstanceVar_zpsef1b807b.png" border="0" />

    And the event like this:

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/RedInstanceEvent_zpsd3cd9594.png" border="0" />

    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!

  • 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.

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

    <img src="http://i1287.photobucket.com/albums/a637/Victoria_San_Miguel/NewEvent1_zps6cca1265.png" border="0">

    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!

  • 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?

  • LittleStain Hey LittleStain! I will try to answer all your questions in order.

    1. This I didn't even realize until just now. I was thinking that each time I clicked on a red block it would add one to redblockready, so I set it to bigger than or equal to to compensate for people accidentally clicking more than once. But your right this is not the case when using set to, thanks for calling it to my attention. Although this shouldn't cause the event to fail, it's just not necessary.

    2. For this I did not know that it would matter because in my mind a global variable should be applied across all sprites and their instances kinda covering all bases.

    3. Originally my event had a pick overlapping Red.X and Red.Y condition. With that my hopes were that it would pick the red block instance I clicked on and then move it to the location I clicked on next. The later screenshot of my event in this post was something that I was trying to understand from BluePhaze but I believe I implemented it wrong or incompletely. I'm not very proficient with strings/syntax yet.

    4. For your last question on why I'm using a third party plugin for pathfinding, it's because this one is far better for grid-based square by square movement. The C2 built in one moves sprites smoothly and requires monkeying with to get what I want for this game, and even then it wont work like I want 100%. So for now I'm sticking with the one I'm using.

    In conclusion, I hope my answers made sense and if you could help me out with my problem I would be very grateful! Thanks for your time.

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