How do I make my actor spawn when touched once, and stop spawning when touched twice.

I would like my actor to spawn when touched and stop spawning when touched twice.

Best Answers

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2014

    Can you explain this a bit more? Do you want the actor to spawn other actors? Do you want this to happen inside a timer (e.g. every second) until the second touch? And do you mean a double-click/tap?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    I mean I want the actor to spawn other actors when I tap on it. Then when I tap twice on the spawning actor I want the spawn to stop. The actor is spawning a menu type to show the user what items he has collected.

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    Can this be done???

  • http_gamesaladhttp_gamesalad Member Posts: 1,340
    edited November 2014

    Okay make an integer game attribute call it tap

    then do

    when touch is pressed
    do (change attribute behavior ) game.tap to (game.tap+1)%2 (if someone taps it again after the second time it'll start spawning again) If you just want it to happen only once do game.tap to game.tap+1

    Then where your spawner is make attribute on top and say
    game.tap < 2
    do spawn

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    set the game.tap to 1 so as soon as you press it it stops the spawn

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    You know ill just make a template as soon as I'm out of school cause I don't think I explained that well! Give me a few hours or less :)

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    Thanks. Will it take away the already spawned actors? That would be great if it could.

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    do you want it to spawn continuously when its touched once or?

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    so i know how to set it up

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    I would like to to spawn when touched, and take away spawn (what has already been spawned) when touched again. Then when touched again, spawn, and so on.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2014

    Hi @sswisehaupt‌ Try this then: make an integer called SpawnLiveorDie

    In your actor to be spawned, the Prototype one in the Inspector, put in its Rules:

    -- any position and movement behaviours for your spawned actor
    When SpawnLiveOrDie is 2
    Change Attribute SpawnLiveOrDie to 0
    Destroy
    

    Now in the actor that spawns:

    Rule: When touch is pressed
    Rule: -- nested in above-- When SpawnLiveOrDie is 0
    Spawn 
    Change Attribute SpawnLiveOrDie to 1
    Otherwise
    Change Attribute SpawnLiveOrDie to 2
    

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    l will try that. Thanks a lot. I had been stumped. Let you know if it works, but might not be until tomorrow.

  • http_gamesaladhttp_gamesalad Member Posts: 1,340

    There you go!

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    Thanks for all your replies. I have set your dropbox spawner template up like shown, but for some reason its not working. When I preview the template you sent, thats what I want, to stop spawning and destroy all spawned actors. Not sure what I am doing wrong. Gyroscope, it flashed my spawned actors and nothing else.

  • sswisehauptsswisehaupt Member, PRO Posts: 76

    I got it to work. I'm so excited. Thank you very much. I went back and checked all my rules and one was off. I used the spawner template. Thank you so much.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    @sswisehaupt said:
    Thanks for all your replies. I have set your dropbox spawner template up like shown, but for some reason its not working. When I preview the template you sent, thats what I want, to stop spawning and destroy all spawned actors. Not sure what I am doing wrong. Gyroscope, it flashed my spawned actors and nothing else.

    Glad you got it sorted by using the template from @http_gamesalad :smile:

    If, in my version, the spawned actor flashed and disappeared, my guess is you didn't nest the rules, or you set SpawnLiveorDie to 1, not 0 to start. Either way, it doesn't matter now, you're sorted.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.