Fundamental Logic problem

wormilwormil Member Posts: 127
edited March 2012 in Working with GS (Mac)
I have some code as follows:
Rule "self.a" < 100 then
change attribute a = 110
rotate

Below that rule I have a second rule

Rule "self.a" > 100
change attribute a = 110
move


so I have two separate rules, the first one triggers because a is 0
a gets set to 110
the actor rotates

second rule triggers because a > 100
a still is 110
the actor moves

the actor never stops rotating. Why is this? If i make it happen say on a mouse.x position < 100 and > 100, they are independent and mutually exclusive as I'd expect.

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited March 2012
    You need to have a rule that sets the rotation velocity back to zero. As well as the move. Put those rules in the otherwise area of the first rule.
  • MotherHooseMotherHoose Member Posts: 2,456
    good idea to put a Display Text behavior on your actor … Text field expression: self.a

    that way you can see when things trigger and why they continue … and then fix your rule

    the first set of rules are virtually identical … as are the second set … and will result in the same results almost immediately
    turn off some of them (comment out) … to see which ones you really need … and which ones actually trigger the action/event

    as @FryingBaconStudios said:… if there are only 2 conditions … use the Otherwise: section of one rule

    @};- MH
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Actually @motherhoose I use otherwise a lot for multiple conditions. I have some with like up to 15, like one of those Russian dolls...lol
  • MotherHooseMotherHoose Member Posts: 2,456
    edited March 2012
    yes … I do too … @ FryGuy … but when you have never done so … doing it once … will open up the advantages of using Otherwise:

    perhaps I should Edit that to 'as'

    can I please have the babushka dolls?
    image


    @};- MH
  • wormilwormil Member Posts: 127
    edited March 2012
    I understand I can use a single case for this, I do have the display on the actor, it displays 110.

    For what it's worth, it does the exact same thing in otherwise.

    If you change it to be

    device.mouse.x < 100
    rotate

    device.mouse.x > 100
    move

    they do exclusively what they are supposed to do.

    My question is why doesn't the rule update for a variable, unless i put a timer in it?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    You have to put in a rule that changes the rotation speed to 0 in otherwise and the same for move.
  • wormilwormil Member Posts: 127
    Same results.
    Make a new actor
    Add an attribute to an actor
    set attribute to 0

    rule self.a < 100
    rotate
    change attribute self.a 110
    otherwise
    rotate 0 speed

    still rotates.
  • MotherHooseMotherHoose Member Posts: 2,456
    Rotate is a (Persistent Behavior) … meaning that it will continue and continue … i.e. persist in doing so …
    until you tell the computer to stop rotating the actor

    the computer reads that the self.a < 100 … and follows your instructions to rotate
    the changeAttribute: self.a To: is done … but does not affect the persisting rotation behavior

    the changeAttribute for self.a must be handled by another rule separated from the rotating behavior

    Rule: when
    Attribute: self.a ≤ 100
    --Rotate
    Otherwise:
    --Rotate --Speed: 0

    Rule: when
    Event: touch is pressed
    --changeAttribute: self.a To: 110
    --Move stuff (here or in separate rule with condition self.a=110)

    because of the rotation … you will need your move behavior Relative: to scene

    @};- MH
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Thanx @motherhoose my eyes were starting to bleed.... @-)
  • wormilwormil Member Posts: 127
    I resolved what I was looking at. My problem was, as a programmer, I interpret the code to be done as this:

    while true:
    if x < 100:
    rotate
    x = x + 1
    else:
    don't rotate


    Based on the mouse button behavior for rotate where during a button press it would rotate, i assumed the same would hold true for attributes. My mistake :/
  • wormilwormil Member Posts: 127
    Oh and thanks for the help :)
Sign In or Register to comment.