License from €75
DE EN FR ES IT CZ

how to compare position between mc and other characters?

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 8 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
    
    
  2. · 8 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.

  3. · 8 years ago
    I know I am totally new to programing, but I am happy with this little results.
  4. · 8 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
  5. · 8 years ago
    Thank you for the code. I know copy/paste code mess up in the forum I dunno why
  6. · 8 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>
  7. · 8 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 "<"
  8. · 8 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.

  9. · 8 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

  10. · 8 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.
  11. · 8 years ago
    i know but why stitch yourself up if you move on to something else

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?