How can I make and Actor repeat an action more then once?

The way I have my game set up, I have a small hitbox in the bottom corner of the screen. I want to be able to touch the hitbox and that will trigger a "Monster" actor to appear on the screen then fade away.

So far it works but it only work for one time, then I have to reset my game to do it again. I want to be able to do touch the hitbox over and over again and making the actor will appear and then fade away.

This is the code I have.

for Hitbox

Rule:

Touch is pressed

Do

Change Attribute set: game.hitbox
to: true


Then for my ( Monster Actor) I put.

Rule:

If game.hitbox is True

Do

change image set image to: "Monster" Actor


interpolate: Interpolate: self.color.alpha to: 0
for: 5 seconds
linear


Other info my hitbox is a "boolean" and my Monster actor is boolean as well.


So if anyone know what to do let me know.

Comments

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291
    edited November 2013
    The way I have my game set up, I have a small hitbox in the bottom corner of the screen. I want to be able to touch the hitbox and that will trigger a "Monster" actor to appear on the screen then fade away.

    So far it works but it only work for one time, then I have to reset my game to do it again. I want to be able to do touch the hitbox over and over again and making the actor will appear and then fade away.

    This is the code I have.

    for Hitbox

    Rule:

    Touch is pressed

    Do

    Change Attribute set: game.hitbox
    to: true


    Then for my ( Monster Actor) I put.

    Rule:

    If game.hitbox is True

    Do

    change image set image to: "Monster" Actor


    interpolate: Interpolate: self.color.alpha to: 0
    for: 5 seconds
    linear


    Other info my hitbox is a "boolean" and my Monster actor is boolean as well.


    So if anyone know what to do let me know.

    Hey, the reason it is only working once is because once you pressed the hit box and changed the game.hitbox to true, it stays true and won't run the rules again as the attribute is already true. What you need to do is add a rule that changes the game.hitbox back to false. You could do it one of two ways.

    Way 1:
    Set up a timer in a rule and have it say something along the lines of,
    When game.hitbox is true
    After 5 seconds---Run to competition
    Change Attribute game.hitbox to false
    Then after the 5 seconds is up, the attribute is false and the rules will work again and again after 5 seconds.

    Way 2:
    In the monster actor, have it say something along the lines,
    All:
    When game.hitbox is true
    and
    When self.color.alpha is 0
    change Attribute game.hitbox to false

    There are other ways you can do it also. The different ways depend on how you want it to work for your game. The main thing to note here is that you have to have the Attribute reset back to false each time for the rules to run through again! Hope that helps!
  • GamepencilerGamepenciler Artist/Game Developer Member, PRO Posts: 326
    I think you should try using the timer Every time function inside button press.. not sure if it helps..

    Artist/Game Developer / Animator at your service..

  • SocksSocks London, UK.Member Posts: 12,822
    Like Killer Penguin says your rules are looking for when a switch (hitbox) is changed from OFF to ON, the first time you press the button this works fine, the change in the state of the switch is recognised, the second time you try and flick the switch it's already ON so no change is registered so no monsters for you !

    Personally I like to keep code simple so I'd dump all the is-hitbox-true-attribute stuff and just have a rule saying that when the hit box is touched spawn an actor wherever you want.
  • SocksSocks London, UK.Member Posts: 12,822
    interpolate: Interpolate: self.color.alpha for: 5 seconds linear
    Try interpolate to -0.2 over 6 seconds to avoid the little visual 'pop' at the end of the interpolation.
    iOther info my hitbox is a "boolean" and my Monster actor is boolean as well.
    'Boolean’ is a type of attribute / variable, rather than a type of actor, actors can't be boolean.
  • Hey KillerPenguinStudios thanks, for the info... Your 1st way kinda work for me. I manage to get the sound to repeat over and over but I can't get the actor to pop up again and fade away.

    I'm not sure what's wrong. You way seem so simple it should work easy. Do you have any idea what could be wrong?

    I know the way I normal do my fade away. I 1st use the image of the actor and place it on the screen, then I cover it with a blank actor. Not sure if that the right thing to do, but it got me this far.
  • future_games_101future_games_101 Member Posts: 58
    what you have to do is after the monster moves. You need to change your (boolean) game.hitbox to false. Like this,

    for hitbox
    Rule:
    if touch is pressed
    Do:
    Change Attribute: game.hitbox to true

    for monster actor
    Rule:
    if game.hitbox is true
    Do:
    Change image set image to "monster" actor
    Interpolate: interpolate: self.color.alpha to 0
    for 5 seconds
    linear
    change attribute: game.hitbox to false
  • grimmagelolgrimmagelol Member Posts: 18
    Easy way socks

    rule
    touch

    DO
    timer
    After 1 sec

    Spawn actor

    ------------------------
    Hard way
    Attribute spawn monster Boolean set to false

    Rule in Hitbox actor
    touch
    Attribute Spawn monster = false

    DO
    Spawn actor
    Timer for 1 sec
    Change attribute to true

    timer After 1 sec
    Change attribute to false

    Should only work when your attribute is false which it should start off as and turn to true than back to false in 1 sec after u click the Hitbox actor.

    As for changing its alpha id just destroy the actor at a certain point or time that way there wont b actors build up in the background with 0 alpha.

    In the monster actor put rules to make it move where u want

    Also u can add a spawn limit by changing the attribute to integer and making the rule Less than or equal to a certain number. Its just a little harder.
    In the monster actor u will have to add change attribute to game.SpawnLimit to game.spawnlimit+1 And when the monster gets killed change attribute spawn limit to -1
    So u will be able to spawn up to a certain amount of enemies.
Sign In or Register to comment.