GameSalad

how to spawn actors that are planned before

hey guys im workin on something new
so basically im not sure how to get on this certain thing which is like
its basically a match game you have to match the random shapes that pop up either by the shape or color

so how do i get that when two are lets say red cubes are spawned and the player touches both of them get destroyed. im still working on the whole spawning but i felt like if i can't get the main part of the game functional which is them matching i can't work on more stuff

any help please?

Comments

  • tatiangtatiang Posts: 10,546Member, Sous Chef, Senior Sous-Chef, BASIC
    edited March 19

    I've been around here a long time and I'm not usually one to recommend a template immediately but in this case, it's probably easiest to start with something that already works and adapt it for your use:

    http://gshelper.com/woocommerce-search/keyword/match/search-in/product/cat-in/all/search-other/product

    But to answer your question, you can do something like this:

    When Touch is Pressed
         When game.touchCount=0
              change attribute game.firstTouched to self.myColor
              change attribute game.touchCount to 1
         Otherwise
              change attribute game.secondTouched to self.myColor
              change attribute game.touchCount to 2
         When game.touchCount=2
              When game.firstTouched=game.secondTouched
                   [it's a match!]

  • RawanAlodehRawanAlodeh Posts: 44Member

    @tatiang said:
    I've been around here a long time and I'm not usually one to recommend a template immediately but in this case, it's probably easiest to start with something that already works and adapt it for your use:

    http://gshelper.com/woocommerce-search/keyword/match/search-in/product/cat-in/all/search-other/product

    But to answer your question, you can do something like this:

    When Touch is Pressed
         When game.touchCount=0
              change attribute game.firstTouched to self.myColor
              change attribute game.touchCount to 1
         Otherwise
              change attribute game.secondTouched to self.myColor
              change attribute game.touchCount to 2
         When game.touchCount=2
              When game.firstTouched=game.secondTouched
                   [it's a match!]

    ive tried what you said, but both actors get destroyed on first touch

  • pHghostpHghost London, UKPosts: 1,755Member

    Yes, the reason is that once you press it once, game.touchCount is changed to 1 and the otherwise section is triggered as well. You need to work around that.

  • RawanAlodehRawanAlodeh Posts: 44Member

    @pHghost said:
    Yes, the reason is that once you press it once, game.touchCount is changed to 1 and the otherwise section is triggered as well. You need to work around that.

    would it be simpler if for example i have two actors of each, lets say red. and in each of them ill create a rule that if its touched change attribute, and the same in the other actor. and a rule in both that if both attributes are changed they get destroyed. or will this complicate things when i spawn with tables?

  • tatiangtatiang Posts: 10,546Member, Sous Chef, Senior Sous-Chef, BASIC

    @pHghost said:
    Yes, the reason is that once you press it once, game.touchCount is changed to 1 and the otherwise section is triggered as well. You need to work around that.

    It shouldn't be. That's the whole point of using Otherwise. If a rule says:

    When x=1
         do A
         change x to 2
    When x=2
    do B

    Then it will evaluate the second rule right after x is changed to 2 and both rules will trigger ("do A" and "do B"). But using Otherwise:

    When x=1
         do A
         change x to 2
    Otherwise
         do B

    Should only trigger the first condition and "do A."

  • RawanAlodehRawanAlodeh Posts: 44Member

    @tatiang said:

    @pHghost said:
    Yes, the reason is that once you press it once, game.touchCount is changed to 1 and the otherwise section is triggered as well. You need to work around that.

    It shouldn't be. That's the whole point of using Otherwise. If a rule says:

    When x=1
         do A
         change x to 2
    When x=2
    do B

    Then it will evaluate the second rule right after x is changed to 2 and both rules will trigger ("do A" and "do B"). But using Otherwise:

    When x=1
         do A
         change x to 2
    Otherwise
         do B

    Should only trigger the first condition and "do A."

    so why do both actors get destroyed when i touch one?

  • tatiangtatiang Posts: 10,546Member, Sous Chef, Senior Sous-Chef, BASIC
    edited March 24

    Hmm, sorry, it might have to be:

    When game.touchCount=0
         When Touch is Pressed
              change attribute game.firstTouched to self.myColor
              change attribute game.touchCount to 1
    Otherwise
         When Touch is Pressed
              change attribute game.secondTouched to self.myColor
              change attribute game.touchCount to 2
         When game.touchCount=2
                When game.firstTouched=game.secondTouched
                    [it's a match!]

    I didn't test this or the previous suggestion... both were off the top of my head so my apologies if this isn't quite right. Should be close though. ;)

Sign In or Register to comment.