Change values on character moves

  • #1, by dror-ben-hurTuesday, 22. May 2018, 16:33 2 years ago
    Hi all,
    I wold like to update some value according to my character moves or position, how can I achieve this?

    10X! 

    Newbie

    27 Posts


  • #2, by ke4Tuesday, 22. May 2018, 20:10 2 years ago
    Not sure what you are trying to achieve here.

    You can add actions directly to character animation frames or there's the option called "start action after animation is finished" and you can link some actions there.

    There's no event handler for walking as far as i know tho you can get the information via this line of code
    game.CurrentCharacter.State
    1

    Where 2 is standing & 3 is walking. So you can create your own with the main loop.
    function functionName()
        --your code here
    end

    registerEventHandler("mainLoop", "functionName")
    1
    2
    3
    4
    5

    Key Killer

    810 Posts

  • #3, by dror-ben-hurWednesday, 23. May 2018, 09:51 2 years ago
    Thank you @K4e.
    In general the link you provided is very useful.

    I am trying to achieve a fixed text that show the player "depth water level". 
    That level is changes according to the character position.

    Any way, I try your suggestion .
    Thanks again.

    Newbie

    27 Posts

  • #4, by afrlmeWednesday, 23. May 2018, 12:29 2 years ago
    Please try to include more details when asking for help mate. Your initial post didn't really provide much information on what you wanted other than something to do with values & movement.

    Are you talking about a percentage value between 2 points or values determined by range values? i.e: if character is > 100 and <= 200 then character is x distance down? Or do you just want to display the actual y position of the character? If it's the latter then you could use the Lua mainLoop function to update & store the y position of the character inside of a value. You can use the same method as the playtime thing for displaying the value.

    Imperator

    6773 Posts

  • #5, by dror-ben-hurWednesday, 23. May 2018, 13:13 2 years ago
    Yes you are right, I was try to relieve the reader from too much info, next time I explain my self butter.

    As a solution I was using this Lua code combined with main loop:

    char = game:getLink(VGameCurrentCharacter)
    pos = char:getPoint(VCharacterPosition)
    level = -1*(255 + (pos.x / 1000))
    level = round(level,2)
    Values["water_level"].String =tostring(level)



    Newbie

    27 Posts

  • #6, by afrlmeWednesday, 23. May 2018, 13:28 2 years ago
    I don't understand what your calculations are doing, then again, math has never been something I've been very good with.

    So the character swims horizontally in this scene as opposed to vertically down?

    x = horizontal
    y = vertical

    Anyway... quick note: you could shorten the script by a few lines if you wanted. There's really no need to declare variables for everything & there's no need to use the old getObject method either.
    level = -1 * (255 + (game.CurrentCharacter.Position.x / 1000) )
    level = round(level, 2)
    Values["water_level"].String = tostring(level)
    1
    2
    3

    Imperator

    6773 Posts

  • #7, by dror-ben-hurWednesday, 23. May 2018, 14:15 2 years ago
    Good note, I will make the replace in my code.
    You are the best...!

    Newbie

    27 Posts

  • #8, by MachtnixWednesday, 23. May 2018, 14:21 2 years ago
    You can also use action areas I think.

    Key Killer

    995 Posts

Write post