How do I pick from a set of 4 and move that item?

Get help using Construct 2

Post » Mon Mar 27, 2017 10:46 pm

My question actually has several parts. First, I understand drag and drop behavior, but decided I didn't like it, so opted for setting the selected item with a "-picked" flag (red-picked=1, blue-picked=1, etc.) The first issue I have is, I used to standard programming, where I would just get a reference to the object clicked on, then on then check if the place to drop is a good spot and place it. In this environment, and for my situation, I'm having to repeat the same initial object selection for every single item (there are 4), and for each of the 4, I have to set ALL the "-picked" flags accordingly. I don't know if I can implement this with a group somehow to minimize the code. The point is, I only care that one of the items was selected, then move that item to the next spot that the mouse has selected. In summary, I managed so select an item by clicking and move it to the destination, but the code for working with 4 different objects seem like overkill and would like to optimize it if I could.

Next problem... what I'm creating is like the a game that I think was called, Master Mind. There would be a hidden combination of 4 color pegs. You have perhaps maybe 10 chances to guess the proper order of the colors. So, I have to check that all 4 colored sprites have been moved, then test for correctness, then allow them to be moved again if they were incorrect and they have turns left. The destination for the moves from one iteration to the next are simply a set of sprites, and these can me moved forward for the next move if the user fails to guess the correct order. And, I already know how to select->drop (as cluttered as that seems), but my bigger problem is, I'd like to leave the current colors at their current locations and place a spawned copy at the target location for the next move, so the user can see all there previous tries. This suggests some kind of spawn operation, but then the complication is, all of the older copies cannot be selectable! Do I restrict the click by Y, since each try moves vertically up the playing field, so only the sprites near the top can be moved (If mouse clicked -and- Mouse.Y > blahblah | set color's to picked flag)?

In the meantime, I'll keep trying alternatives, but any suggestions would be great! One thing I'm trying to wrap my head around is, if I spawn a bunch of red items, and they click on a red item, then how will it know which red one to move to the target location.... and thus this multiplied times 3 other colors involved.

BTW... I currently don't uses instance variables, but these might help, solve some of my code blot, by being able to implement my objects differently, and be able to loop through set of them and examine their instance variables, for values that would help me determine the processing that needs to be done, and help me identify the object to act upon.
B
5
Posts: 5
Reputation: 235

Post » Mon Mar 27, 2017 10:57 pm

I'm going to assume you're relatively new to Construct 2, so first I'll direct you to the manual - https://www.scirra.com/manual/75/how-events-work, and hope you have done the tutorials.

It's going to be a bit difficult if you're a traditional programmer moving to Construct, as you will find that a lot of things you are trying to do are simpler than you might think. Basically, Construct will take care of a lot of lower level stuff for you behind the scenes (such as everything you mention in the last paragraph).

Specifically regarding your questions - In your event conditions, if you used "On Mouse clicked RedItemSprite", only the one you clicked on will be "picked", and any actions in that event will only apply to those instances that have been picked by the conditions specified.

So if you're setting flags, only the instance you click on will be picked and have its flag set. You can use a seperate event that runs every tick to keep the instance with its flag set positioned under your mouse at all times. On release, you can reset the flag.

Regarding limiting which of your instances can be "picked up" - there are many ways to do this, it is up to you to set the condition under which it can be interacted with. Another instance variable as a flag would do nicely. Another useful technique that comes in handy in a lot of cases is to use an invisible helper sprite. Place this invisible sprite over the ones you want to interact, and in the event that lets you pick up items, add the condition that your mouse has to be over this helper sprite. If not, then that event won't run.
Mistakes were made.
B
48
S
23
G
107
Posts: 1,576
Reputation: 60,168

Post » Fri Mar 31, 2017 6:27 pm

SOLVED: First, to clean up my event sheet, instead of using different flags for different states in the game, I have 1 state value to check and set constants to represent each state, use to set "state" throughout the phases of the game. I had to learn how to properly/effectively use sub-events, under each event that is used to test the current value of "state". Also learned how to implement loops, which solved another problem. There was also a lot of repeated logic for each color, so I learned how to create functions to reuse that logic.

Finally, to solve my turn taking problem, I simply move the target slots up (they're at the bottom of the screen). Then movement of a color is done by spawning a dummy instance of that piece at the working piece's position, then moving the working piece to the target. So, in this fashion, each turn can always use the same slots and pieces.

So, I made a lot of head way and feel much better about Construct 2. There are some things you have to shift in your brain if you're a traditional coder, because you have to be more particular about how you implement things in the event sheet. I'm now at point of just figuring out what I want to do at the WIN and LOSE states of my game.

And, though I have plenty of experience programming (25 yrs), this will be my first COMPLETED Construct 2 casual game. My goal is learn how to wrap it as a hybrid app for android and test it on a device or 2 (phone and table). Then, make any adjustment to the code to better fit on both devices.
B
5
Posts: 5
Reputation: 235

Post » Sun Apr 02, 2017 8:24 pm

@3dski

I was reading your first post. I noticed things like :

"having to repeat the same initial object selection for every single item"
"spawned copy at the target"
"spawned copy at the target"


So, i made this, up to you if you read it.
https://www.dropbox.com/s/j572pceegiy4u ... .capx?dl=0
B
33
S
18
G
27
Posts: 2,431
Reputation: 20,326


Return to How do I....?

Who is online

Users browsing this forum: ksiads and 2 guests