coding trouble with matching game

RVvDRVvD Member, PRO Posts: 36

Today I believed I had solved my problems with the non matching coding but now one pair matches perfectly and the other I need to click a few times before it matches. I have attached a zipped folder containing what I have been working on (as it would probably take too long to explain here in typing) any help would be appreciated.
Thanks,
Rachel.

Comments

  • ThoPelThoPel GermanyMember, PRO Posts: 184
    edited August 2015

    It is very hard to understand your code, because

    • all behaviors have the default name.
    • your actor (e background) spawns an actor (ebackground1) which spawns an actor (e) which spawns an actor (e spawn).
  • RVvDRVvD Member, PRO Posts: 36

    Ok, sorry about that ThoPel, my matching game uses letters so I was copying which background would be which letter so e background was for the letter e and so on...

    Anyway I have renamed them now and if you can take another look maybe it's better.

    The initial backgrounds are the backgrounds for the initial show of the images and the game backgrounds are the ones used in the actual game so that when touch is pressed it reveals the image underneath.

    It is within the butterfly actors that I have tried to figure out the matching and non matching coding. Hope this helps.

  • ThoPelThoPel GermanyMember, PRO Posts: 184
    edited August 2015

    The pink matches correct - right?

    I think you have a problem with the assigning of your variables.

    • Why is CARDIDA only used / assigned to the Pink Butterfly?
  • RVvDRVvD Member, PRO Posts: 36

    Hi ThoPel, the CARDIDA and the CARDID were game attributes that I was using to try and match them while the other game attributes (same but lower case) cardid and cardida were non matching.

    But at the moment in this example they CARDID and CARDIDA aren't being used for anything because I found that the one set of attributes worked fine. So basically these attributes aren't being used at all it is the lower case cardid and cardida that are being used in the coding. So they will be deleted as they are not doing anything. This is what is happening:

    red butterfly= change att: game.cardid to: 1
    pink butterfly= change att: game.cardid to:2
    red butterfly 2= change att: game.cardida to:1
    pink butterfly 2= change att: game.cardida to:2

    so for a pair to match, the code for the red butterfly:

    Rule: if:game.cardid =1 and if:game.cardida =1
    then set game.matchfound to true
    then new seperate Rule: if:game.matchfound is true
    then... fade and reset cardid and cardida attributes.

    Same as above for the pink butterfly but the attributes =2 (instead of 1)

    Also a new seperate rule for the non matching coding for the red butterflies:
    Rule: if game.cardid>1, if game.cardida>1
    ...then the next part of the rule for the red butterfly..do:
    Rule: if: game.cardid !=1, if: game.carida!=1
    Change Att: game.cardid to:0, Change Att: game.cardida to:0, Destroy

    Same as above for the pink butterfly but game.cardid=1and game.cardida=1 (instead of >1) for the other part Rule: if game.cardid!=2, if: game.cardida!=2 (instead of !=1)

    Both of the pairings match when you click on them but only if they are the first match you select, so if you match the red butterfly 1st it works perfectly and the same for the pink.

    but if they are not the first to match you have to click a few times for the second match to work.


    This is the problem I am having they both can match (if they are the first match selected) but if they are not the first match selected it requires you to click a few times before it does match and fade away as it should. I have added a few screenshots.

    Sorry for the explanation being a bit long, but I hope it helps you understand where I am coming from .

  • ThoPelThoPel GermanyMember, PRO Posts: 184
    edited August 2015

    @RVvD said:
    at the moment in this example they CARDID and CARDIDA aren't being used for anything

    Maybe you should clean up the code before you ask other to control it. :|

    Red Butterfly

    Pink Butterfly

    The variables CARDID and CARDIDA are used!

  • RVvDRVvD Member, PRO Posts: 36

    Sorry, I am still new to all this. That was left over from something I was trying to do because I have probably tried a hundred different ways to sort out this matching an non matching coding I am bound to have missed something as I have been going through.

    As I have spent a couple of weeks on this and this is the only thing that is stopping me from going forward with my game. but it doen's make any difference to my problem as you can see by the red butterfly coding they are meant to be the lower case versions, that should have been changed back when my idea didn't work. But even with them being wrong the way they are they haven't made any change with the game.

    If you still want to help I will attach the cleaned up version here. Sorry again it was simply just something I had missed. Thank you for pointing it out =)

  • ThoPelThoPel GermanyMember, PRO Posts: 184
    edited August 2015

    No problem.

    With a clean code the reason is very quickly visible - it's the order of the behaviros. You could add two actors to your scene, one should display the value of "cardid" and the second actor the value of "cardida".

    If you touch the second pair, the values will be reset to 0. So the first touch is used to reset the values and that's the reason why you need to touch twice.

    Are you planning to build a really big memory (e.g. 20, 100, ... pairs) or all the time only two pairs?

  • RVvDRVvD Member, PRO Posts: 36

    Hi Thopel, thanks, the memory game I am building is going to be using a copyrighted illustrated alphabet so the last level would be 26 pairs.

    First level abc 3matches, second level 5 matches fourth level 21 matches then the last obviously all of the alphabet.

    So how would I make them reset only on the second touch?

  • ThoPelThoPel GermanyMember, PRO Posts: 184

    Hi @RVvD ,

    your problem is that the spawned butterfly resets the cardid + cardida and destroys itself. That was the reason why I wrote "order of the behaviros". You need to reset the cardid + cardida before you spawn the second, third or ... pair.

    I would not reinvent the wheel, just buy a memory game and customize it.
    e.g. Memory Match Template

  • RVvDRVvD Member, PRO Posts: 36

    Okay, thank you so much for all your time & help =) I'll see what I can do.

Sign In or Register to comment.