how to compare position between mc and other characters?

  • #10, by nerdFriday, 14. December 2018, 10:36 5 years ago
    This works:

    function distanceScriptTry (mc, opponent)
    
    standingRight =  getObject("Conditions[standingRight]") 
    standingLeft =  getObject("Conditions[standingLeft]")
    mc = getObject("Characters[MC]")
    opponent = getObject("Characters[opponent]")
    
    
    if mc.Position.x < opponent.Position.x
    
    and
    
    mc.Position.x - opponent.Position.x >=-300
    
    then
    
    standingLeft:setValue(VConditionValue, true)
    
    else
    
    standingLeft:setValue(VConditionValue, false)
    
    end
    
    if mc.Position.x > opponent.Position.x 
    
    and
    
    mc.Position.x - opponent.Position.x <=300
    
    then
    
    standingRight:setValue(VConditionValue, true)
    
    else
    
    standingRight:setValue(VConditionValue, false)
    
    end
    end
    
    

    Forum Fan

    147 Posts


  • #11, by afrlmeFriday, 14. December 2018, 11:34 5 years ago
    Why is everything on a single line with an empty line in between?

    The reason your first didn't work is because you didn't correctly query if the attackers x position was greater than or less than the opponents x position. Also you added the attackers position & opponents position values together instead of subtracting.

    Imperator

    7278 Posts

  • #12, by nerdSaturday, 15. December 2018, 11:54 5 years ago
    I know I am totally new to programing, but I am happy with this little results.

    Forum Fan

    147 Posts

  • #13, by afrlmeSaturday, 15. December 2018, 12:23 5 years ago
    I tried to share a tidied up version of your script, but the forum cms kept messing it up.

    local mc, opponent
    
    
    
    function distanceScriptTry(mc, opponent)
    
       mc = Characters[mc]
    
       opponent = Characters[opponent]
    
     
    -- + --
      if mc.Position.x < opponent.Position.x and opponent.Position.x - mc.Position.x <= 300 then
    
          Conditions["standingLeft"].Value = true
    
          Conditions["standingRight"].Value = false
    
       elseif mc.Position.x > opponent.Position.x and mc.Position.x - opponent.Position.x <= 300 then
    
          Conditions["standingLeft"].Value = false
    
          Conditions["standingRight"].Value = true
    
       end
    
    end

    Imperator

    7278 Posts

  • #14, by nerdSaturday, 15. December 2018, 12:54 5 years ago
    Thank you for the code. I know copy/paste code mess up in the forum I dunno why

    Forum Fan

    147 Posts

  • #15, by afrlmeSaturday, 15. December 2018, 13:15 5 years ago
    it was deleting half of the code & stripping <these> <these> from the code.
    </these></these></div>

    by the way, you could use a value instead of 2 conditions. 0 could be left & 1 could be right. less if queries needed.

    oh look the forum broke again. >:|
    <these></these></div>
    <these></these></div>

    Imperator

    7278 Posts

  • #16, by NigecSaturday, 15. December 2018, 14:09 5 years ago
     having the variable the same name as the condition isn't good
    some programing languages its a bad thing

    yeah i noticed i was getting ";" added to code after "<"

    Key Killer

    627 Posts

  • #17, by afrlmeSaturday, 15. December 2018, 14:20 5 years ago
     having the variable the same name as the condition isn't good
    some programing languages its a bad thing

    yeah i noticed i was getting ";" added to code after "<"

    nah, it wouldn't matter in his script example as the variable is a variable & the condition name is a string.

    Lua is case sensitive, as I believe I already mentioned the other day on discord.

    Imperator

    7278 Posts

  • #18, by NigecSaturday, 15. December 2018, 14:24 5 years ago
    I wouldn't do it.. the case is the same btw
    standingRight =  getObject("Conditions[standingRight]")
    C# would be unhappy about it, likewise Actionscript so I'd use unique names regardless

    Key Killer

    627 Posts

  • #19, by afrlmeSaturday, 15. December 2018, 14:53 5 years ago
    But it's Lua script. I removed those from the tidied up version of his script I posted anyway. I didn't see the need to declare the conditions as variables. It's actually faster/better when you don't declare anything as variables.

    Imperator

    7278 Posts

  • #20, by NigecSaturday, 15. December 2018, 16:50 5 years ago
    i know but why stitch yourself up if you move on to something else

    Key Killer

    627 Posts