How often are codes executed

kapserkapser Member Posts: 458
edited November -1 in Working with GS (Mac)
I couldn't find tutorials about how GS function so I'm asking this here.

I'm having an enemy go right when player is at his right or simply moving in his direction based on player's coorindates, and enemies just seem to not update the direction it's going it or try to change about every few seconds and go back to the originally chosen direction.

I'm wondering if there's something I did wrong, and how often the codes in an actor are executed. How long is a step? Are some type of codes only executed every seconds? Do I need to do something in particular to update actions or change of attributes?

Any tips? Hope the question is clear enough.

Comments

  • outasiteoutasite Member Posts: 417
    You can use the move to attribute.
    And if you want the enemy to follow the player once its in a distance you can do this.

    Rule: actor within distance
    move to actor (or accelerate depending on what you want)
    otherwise
    nothing
  • old_kipperold_kipper Member Posts: 1,420
    Or have a look at the 'Actor constraints in Gamesalad' tutorial

    Kipper
  • kapserkapser Member Posts: 458
    I'm not sure how constraint helps me. I forgot to note that the ennemy actor is a physical object so move-to doesn't quite work and this might be why it's interfering.

    I can get the enemy to start moving in player's direction, but then it acts confused and seem to switch from left to right every half a second even if player is still at his right.

    What I did is make an attribute of player's X coordinate, and I'm making enemy actor accelerate left if X is smaller than player's X position, and right if it's bigger, but it doesn't seem to work quite well.

    EDIT: What I realized is that the enemi code seem to work, but it will always follow the starting position of the player, which relate a little to the original question: A code in my player actor change the game attribute to player's position but it doesn't seem to update. How do I get this change attribute behavior to happen every step during the game and why does it happen only once?

    btw I can't find any within distance rule in GS but I guess it can be done with some calculations.
  • kapserkapser Member Posts: 458
    I fixed my problem by using a timer. Thanks for help!
  • old_kipperold_kipper Member Posts: 1,420
    I think this would work-

    use a timer set to every> 0 secs in the player to put the player self position x and y into a pair of game number attributes. Then use a pair of constrain attributes to in the enemy to tie those values to the chase rule you want to use to chase towards player.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    You guys are making this WAY to complicated.

    Constrain Attribute is a behavior that is constantly running you can use it a few different ways.
    but whatever you put in there is will constantly check and update itself basically instantly

    Change Attribute happens once each time it is loaded. so if its in a rule each time that rule is triggered the change attribute will load. But if its is just placed freely in the actor it will only happen the first time the actor loads.

    The rules are executed each and every time they trigger. and there is no time frame between them triggering. however it reads the rules and behaviors from the top down. so on occasion if you have a lot of rules in your actor you want to keep the rules being used the most near the top.

    For what you want to do with tracking positions of actors yo want to make a Real Game Attribute for the x and y position of each actor

    and then use a constrain attribute behavior like this preferable near the top of your rules list.

    Constrain Attribute game.Actor1.X to self.position.x
    Constrain Attribute game.Actor1.Y to self.position.y

    Now actor1's position will constantly be matched to a game attribute and all other actors in the game can have rules built to respond to those coordinates.

    ___________________________________________________________________________________
    Project Help from Tenrdrmer Click Here

    GS BubbleBall Template HERE!!
    Stacks Level Selection Template HERE!!
    Expanding Option Menu Template HERE!!
    Tenrdrmer's Menu # 3 HERE!!
    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • kapserkapser Member Posts: 458
    The core of the problem was because I didn't know Change Attribute was a once only action. Problem is fixed now, thank you very much for additionnal informations tenrdrmer.

    Thanks to everyone!
Sign In or Register to comment.