Changing the same attribute with the one touch

How can i change the same attribute (e.g. Jump) . I want to make my game control easier so i want player to be able to control it with one touch only . When player taps once , the attribute changes to 1 and when the player taps again , the attribute changes to 2. How can i do it with the same touch? (e.g. touch is outside).

Comments

  • EpicoreGamesEpicoreGames Member Posts: 188

    I have tried
    When attribute = 1
    Touch is Outside

    Change attribute to 2

    and

    When attribute = 2
    Touch is Outside

    Change attribtue to 1

    But the problem is they change at the same time . Just as it has been changed to 2 it also detects the current touch as OUTSIDE then it changes back to 1 again...

    I've put a timer in it too but doesn't work
    Like :

    When attribute = 1

    Timer | after 0.01 second
    Rule | touch is outside

    Change attribute to 2

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2015

    When player taps once , the attribute changes to 1 and when the player taps again , the attribute changes to 2

    If this is really what you want (??) then you can simply have a rule that says When touch is pressed change attribute to attribute + 1. Set the attribute to 0 as the default value, then on the first press it will change to 1, on the second press it will change to 2.

  • EpicoreGamesEpicoreGames Member Posts: 188
    edited August 2015

    But what i need to do with the attribute is :
    when attribute = 1 , moves upwards...

    when attribute = 2 , moves downwards...

    So I must reset the attribute back to 1 after the attribute is 2 and the player taps it .

    The actor always needs to moves either upwards or downwards...

    I thought maybe i can let the actor moves upwards when the attribute = even number and let the actor moves downwards when attribute = odd number ... but how can i do that?

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2015

    @EpicoreGames said:
    But what i need to do with the attribute is . . .

    Make an integer attribute 'X'

    Rule: When mouse button is down:
    --Change X to 1-X

    Move: 90°: Speed: 100 *(((1-X ) *2)-1)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited August 2015

    I would suggest using Boolean attributes.

    A Boolean attribute just has two values (True or False).

    That way you can just set Boolean attribute called "MoveUp?" to true or false.
    Then you can have a rule that states when "MoveUp?" is true, the actor moves up. And When "MoveUp" is false the actor moves down.

    Here is a quick example.

    Edit:
    Curses! Beat to the punch by @Socks great solution yet again!

  • EpicoreGamesEpicoreGames Member Posts: 188
    edited August 2015

    I am sorry but i don't really understand how the equation works : (((1-X ) *2)-1)
    How does it change the value back to 1 or 0? And why the speed needs to times that equation?

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2015

    @EpicoreGames said:
    I am sorry but i don't really understand how the equation works : (((1-X ) *2)-1)

    Start with a default of 0 (the default value of a new attribute) and run it through the maths, there's nothing complex there, just basic subtraction and multillication.

    In fact in hindsight you can reduce the equation down to just (x*2)-1

    @EpicoreGames said:
    How does it change the value back to 1 or 0?

    Simple basic maths ! . . . 1-1 = 0 . . . . 1-0 = 1 . . . 1-1 = 0 . . . . 1-0 = 1 . . . etc

    @EpicoreGames said:
    And why the speed needs to times that equation?

    The equation is very very simple (about the most complicated part is 'multiply by 2') follow the logic through I'm sure you will be able to see what it is doing fairly easily.

  • EpicoreGamesEpicoreGames Member Posts: 188

    I still can't get it ... Can i inbox you for further questions?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @EpicoreGames -- if @Socks great math-based solution is too difficult to implement, perhaps you should consider the logic-based solution I provided. Either way works fine, but its always better to be able to understand how your game works.

Sign In or Register to comment.