Destroying Two Matching Actors Randomly Spawned from Two Different Tables

SuperDanniStoneSuperDanniStone Member, BASIC Posts: 4

Hello Everyone!

I hope this message finds you well!

So, I'm trying to create a prototype matching game and I'm unable to figure out how to get the last component to work.

I followed the YT video: https://www.youtube.com/watch?v=J-60AF68Bxc so that I could spawn four non-repeating actor images on the right side of the screen. Then, I created a second table so that a fifth actor on the left side of the screen would spawn a random image.

Now, what I'm having difficulty doing, is destroying the matching actors. I want to destroy both actors when I drag the matching actor from the right to the one on the left. I am able to drag the actors, so I don't need help with that piece. It's just that once they collide, they are not destroyed. I've managed to destroy the one on the left, but the one I'm dragging isn't destroyed. I tried an attribute stating that if the current left image was equal to the current right image to destroy them... but that didn't work, though at that point I wasn't thinking it would, but I was desperate lol

I'm not sure how to have them destroyed based on the image. Perhaps I went about it all wrong from the start and I made it over complicated. I am new to GS, so while I am able to figure out how to destroy actors based on colors,or to simple have one collide and destroy, I'm not sure how to destroy them using tables. I've tried finding tutorials on YT and googling, and even searching the forums here. But I've been unable to find the answer.

I really want to move on from this prototype, but I really want this to be a learning experience and I don't want to give up. If I need to provide images or something else specifically please let me know.

Thanks so much in advance! Take care,

Danni

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    are the actors linked to a value in a table? if so, maybe a rule that says if they collide and their table value matches, within a timer (after 0.05 sec, run to completion) destroy.

  • SuperDanniStoneSuperDanniStone Member, BASIC Posts: 4

    Hi Bob,

    Oh my god, thank you so much! I don't know why on earth I didn't think to use the table cell value function when I kept telling myself I had to match them somehow! I was trying every other which way to match them. I didn't include a timer though, maybe that was also a reason it wasn't working?

    I'm so happy this finally works and I can move on. Thanks again!

  • SuperDanniStoneSuperDanniStone Member, BASIC Posts: 4

    Aw, I spoke too soon. It's only working sometimes, is my table cell value expression incorrect?


  • bob loblawbob loblaw Member, PRO Posts: 793

    so is this a game where you spawn random cards/icons like in that tutorial (actor2), as well as spawning another random icon (actor1) that you need to match to one of group of random icons? then if you match, the originally spawned icon from the group and the single spawned icon both destroy or do something else?

    if that's the case, you could use two global attributes. one that records the single spawned draggable icon value (eg. spawnedIcon), and one that records the value of the icon that the draggable actor connects with (eg. iconValue).

    just quickly going off the top of my head without doing the logic to check, fine tune and debug. try something like this...

    in the draggable actor (actor1):

    change attribute iconValue to 0

    change attribute spawnedIcon to whatever random value is assigned to this actor that changes its appearance based on that value.

    rule

    when actor1 overlaps or collides with actor2 AND

    spawnedIcon = iconValue

    destroy (or do whatever you want the actor to do)


    in the actors spawned as part of the group (actor2):

    rule

    when actor 2 overlaps or collides with actor1-

    change attribute iconValue (or whatever name you give the second attribute) to the random local value assigned to each of the actors.

    rule

    when actor 2 overlaps or collides with actor1 AND

    spawned icon = iconValue

    destroy (or do whatever you want the actor to do)


    hope that makes sense

  • SuperDanniStoneSuperDanniStone Member, BASIC Posts: 4

    Hi Bob!

    Thanks for your reply! You're correct, here's a screenshot of my prototype:


    So right now one table (CurrentItemTable) will randomly generate a pair of earrings on the left, and a second (ChosenID) for the group of earrings on the holder. I am able to drag the earrings from the right to left. But I ultimately just want the matches to be destroyed once they collide, reset the scene so everything randomly spawns again and keep it doing that. I feel that will get me the minimum viable product I'm looking to achieve :)

    Anyhow, to your post, my tables look like this:


    Like the tutorial, I created an actor called "Pair" it has two attributes "WhichPair" and "WhichImage", the "WhichPair" is set 1,2,3, and 4, for the individual earrings on the right. I have a set of RoundRules (Loop rule) for them like in the tutorial. Then for the pair on the left, I called that actor "CurrentItem" (it has two attributes, "WhichCurrentItem" and "WhichCurrentImage") and I have RoundRules2 for that as well.

    Since my tables create their own rows when randomizing the spawned pairs, I'm not sure how to get it to figure out what the value is at the time in order for them to match ... I hope that makes sense. So in your example: "change attribute spawnedIcon to whatever random value is assigned to this actor that changes its appearance based on that value." I'm not sure what the random value is assigned, or what attribute/expression I need to get it to figure it out.

    I was trying to create a rule that when "Which Pair" and "WhichCurrentItem" were equal that it would destroy them. But that expression didn't work. Then I tried your suggestion for the tables if "CurrentItemTable" was equal to "ChosenID"... which worked, but I think maybe it's only checking the first row every time, instead of all the rows in the first column and that's why it only works sometimes. I don't know how to fix that. I tried a few different things in the expression where it has row 1, column 1.

    At this point I feel like maybe I shouldn't have tried to randomize, but I thought at the time it would simplify things and make it easier lol Maybe this is too advanced for someone just starting out like me. I suppose I could just place the pairs myself and forego the tables, but I was really hoping to learn how to get the random matching piece to work.

    Thanks again so much for your time and help with this!

Sign In or Register to comment.