Is there a better way to program this?

sinbotsinbot Member Posts: 232
edited June 2019 in Working with GS (Mac)

I want a rule that makes it so that if my actor is idle for 10 seconds, an attribute triggers an enemy to pursue it. I have it setup so that it seems to work ok but I would rather have the logic placed in the enemy actor rather than the playable one (to reduce too much programming in the main sprite). I can't think of how to go about this though. Any ideas?


POST NOTE: Actually I don't think the 10 second attribute is working correctly. Wondering if maybe I entered it incorrectly? It's pictured in the 2nd (bottom image).

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    just off the top of my head, the logic i would try is having a global attribute/variable to activate the behaviour that is either an integer or boolean (eg. activateChase or something like that and set it to 0 or false, depending on what type you use).

    in the player, have a self variable called idleCounter (or something like that) and have it preset to 10. then use a rule if [all] self.motion.x = 0, and self.motion.y = 0 then [timer] every 1 second, change idleCounter to idleCounter -1.

    another rule that says if idleCounter <= 0, change activateChase to 1 (or true) otherwise changeActivate to 0 (false).

    have another rule that says if [any] self.motion.x doesn't = 0 or self.motion.y doesn't = 0, change idleCounter to 10

    then in your actor that attacks the idle player, have a rule that says if activateChase = 1 ( or true) do whatever the attack is meant to do.

    that's just a quick thing off the top of my head so hopefully it works. i might try slap together a demo to see if it works. it's similar to logic i have used for scoring, where if you collect something within a certain period of time of collecting something else, you get a higher score added.

  • bob loblawbob loblaw Member, PRO Posts: 793

    try the attached file as a guide to help get your head around it. use left and right arrows to move. the box in the top left is the idle timer. the box below is true/false for enemy attack. player is the white box at the bottom. enemy is top right.

    if you were looking at making the enemy attack like say baron von whatsy in the original bubble bobble, you'd need to add more logic. dang i miss that game.

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

    One problem is that game.Time is a reserved attribute name and that attribute counts up from zero. There is no way to change that value. It's only possible to reference it.

    If you want something to happen after 10 seconds, use an After 10 seconds Timer. Or have a rule set like this:

    When [player moves]
         Change Attribute game.timeStamp to game.Time

    When attribute game.Time ≥ game.timeStamp + 10
         [make enemy active]

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

  • sinbotsinbot Member Posts: 232

    thank you guys! you've helped me correct this.

Sign In or Register to comment.