One works, one doesn't - what's the difference between them?

BacktothisBacktothis Member, PRO Posts: 75
So I have two different ways for dynamically adjusting an actor's position relative to another actor. One works, the other doesn't.

Method 1:
When Any of (self.Position.X != game.OffsetX + game.OtherActorX) OR (self.Position.Y != game.OffsetY + game.OtherActorY)
--> Change Attribute self.Position.X := game.OffsetX + game.OtherActorX
--> Change Attribute self.Position.Y := game.OffsetY + game.OtherActorY


Method 2:
Timer every 0.1 seconds
--> Change Attribute self.Position.X := game.OffsetX + game.OtherActorX
--> Change Attribute self.Position.Y := game.OffsetY + game.OtherActorY

game.OffsetX and game.OffsetY change depending on the state of the other actor. I have confirmed that they are changing when and as they should by a debug actor that displays all these values onto the screen. game.OtherActorX and game.OtherActorY remain static the entire time as intended. One method works and the other only works after the scene is reached for the second time, and after 2 to 5 changes in the other actor's state. What's the difference between them?

Comments

  • BacktothisBacktothis Member, PRO Posts: 75
    Also, the When condition in Method 1 is being triggered. This was verified with a debug. The thing is, although the condition is triggered, the Change Attributes are somehow not triggered. The condition thus stays true permanently, and indeed the debug Display Text message never goes away - until the second time around when the condition starts working as intended.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2014

    Hi, it's probably because the use of a timer in the second situation isn't really a working solution... I think your second method should use Constrain behaviours... you should find it'll be a constantly updated process then.

    Method 2:

    --> Constrain Attribute self.Position.X := game.OffsetX + game.OtherActorX
    --> Constrain Attribute self.Position.Y := game.OffsetY + game.OtherActorY

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Why not just constrain the values instead of having a rule that checks to see if the positions aren't the same and then changes them to be the same?
    Method 1:
    When Any of (self.Position.X != game.OffsetX + game.OtherActorX) OR (self.Position.Y != game.OffsetY + game.OtherActorY)
    --> Change Attribute self.Position.X := game.OffsetX + game.OtherActorX
    --> Change Attribute self.Position.Y := game.OffsetY + game.OtherActorY
    This is the equivalent of saying When x≠5, change x to 5 and y to 10. Once the rule runs, x will become 5 and the rule will no longer be true so y will never change to 10. And even the first behavior is dicey since the rule is invalidated immediately upon running.

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

  • BacktothisBacktothis Member, PRO Posts: 75
    Hmm, totally forgot about the constrain behavior lol. But even if you change x to 5, still the second condition about where y is satisfied. And it's set to run on either of them being true. And the condition stays true permanently because the debug condition never disappears. There's also the odd part where when it cycles back to that scene the second time around, everything suddenly works.
  • BacktothisBacktothis Member, PRO Posts: 75
    Thanks though, constrain works!
  • BacktothisBacktothis Member, PRO Posts: 75
    Hmm odd, well after adding in the constrains (and not touching anything else), now a spawner isn't working that used to be working, and the problem is once again a condition that is being evaluated as true yet nothing inside is being executed (other than the debug Display Text behavior).
  • BacktothisBacktothis Member, PRO Posts: 75
    Well, rebuilt the old version of the project to add the new rules... as far as I can tell these two versions now have the same code and same variable names. Except the rebuilt one works, whereas the older one is evaluating the spawn condition as true, but not executing any of the spawn behaviors (except for the debug Display Text message). So... is there any maybe errant mistake that might be commonly made that could cause a rule to be evaluated as true yet not execute?
Sign In or Register to comment.