LUA, the VS Data Structure, User Commands and the VS Object Model, beginner's headaches!

  • #10, z sebastianThursday, 16. March 2017, 07:33 hodinky 8 years ago
    ah ok. my mistake smile 


    Kapitán

    2346 Posts


  • #11, z LebosteinThursday, 16. March 2017, 12:36 hodinky 8 years ago
    ... because I am having difficulty understanding how to get the information I need out of the documentation
    Ha! You are not the first. Welcome to the club...

    Zabiják klíčů

    621 Posts

  • #12, z F_KalThursday, 16. March 2017, 22:17 hodinky 8 years ago
    Argh, I'm back to being confused! I have a Character Animation on an NPC and while - startAnimation("Animations[anim1]",true) works fine and - startAnimation("Characters[char1].CharacterCurrentOutfit.OutfitCharacterAnimations[anim1]",true) works aswell, the next one that I thought made sense (and also was suggested by @sebastian and @alex if I didn't get it wrong) doesn't work: startAnimation("Characters[char1].CurrentOutfit.CharacterAnimations[anim1]",true) Seems I have to reference it as CharacterCurrentOutfit and not as CurrentOutfit, and same with OutiftCharacterAnimations instead of CharacterAnimations. Any idea why this is happening? Does this have anything to do with the parentheses being outside the path? Perhaps these startAnimation/stopAnimation don't work with shorthands?

    Fanoušek fóra

    107 Posts

  • #13, z afrlmeThursday, 16. March 2017, 22:56 hodinky 8 years ago
    Let's see...

    1. I have no idea why you are adding ",true" at the end of the startAnimation functions.

    2. I believe I've already mentioned that sometimes you need to type out the full data structure name because of conflicts. i.e: other data structure names contain the same words in them. Most of the character ones need to be written out in full.

    This is the most correct example you wrote...
    startAnimation("Characters[char1].CharacterCurrentOutfit.OutfitCharacterAnimations[anim1]")

    Alternatively - same example but quote marks inside of brackets...
    startAnimation(Characters["char1"].CharacterCurrentOutfit.OutfitCharacterAnimations["anim1"])

    ... I prefer writing them with quotes in the square brackets because it allows me to insert Lua variables instead of "name"; which is useful if you are using it inside of a function where the function has an input variable... For example...
    function playCharAnim(c, a)
     startAnimation(Characters[c].CharacterCurrentOutfit.OutfitCharacterAnimations[a])
    end

    I could then call the function inside of another script / execute a script action part like so...
    playCharAnim("Tom", "pick-up_(generic)")

    ... Anyway, hopefully what I've said helps / clears things up a little bit - if not then I'm afraid I'm going to have to :shakeshark: @ you!
    http://img08.deviantart.net/b3b0/i/2006/088/b/a/_shakeshark__by_taimotive.gif

    Imperátor

    7285 Posts

  • #14, z F_KalFriday, 17. March 2017, 02:18 hodinky 8 years ago
    Once again thank you AFRLme! 

    1. As far as I read, true or false (as a second optional param for startAnimation) determines the direction of playback

    2. you did mention that the shorthand version doesn't always work; but I didn't think I'd bump on it so early! Having said that, I don't mind if I have to use longhand everywhere if it works consistently.
    I also didn't realize that you actually could mix the dot(.) notation with longhand paths, which is very handy.

    Then again, now I'm starting to get confused about the V+field_name systax! :-P Is this some even longer form? If CurrentOutfit is shorthand (albeit wrong one), CharacterCurrentOutfit is longhand, then what is VCharacterCurrentOutfit? 

    But let's not bother about this particular one for now! ;-)
    Let's just wrap it up with a big big thank you!

    PS. aha! This inner VS outer quotes thing was puzzling me! Good to know that it's a matter of preference; I too prefer the quotes inside the brackets.


    Fanoušek fóra

    107 Posts

  • #15, z afrlmeFriday, 17. March 2017, 02:57 hodinky 8 years ago
    Longhand is the getObject / setValue methods. They were the only methods available pre 4.x.
    getObject("Characters[name]"):setValue(VCharacterCurrentOutfit, getObject("Characters[name].CharacterOutfits[name]"))

    ... providing I'm remembering correctly. Been quite a while since I've used getObject. Or maybe I forgot the getLink() part - oh well... shorthand is much nicer as I don't have to use getObject, setValue, getInt, getBool, getPoint, getLink, etc.

    Yes, you are correct about true/false statement in startAnimation() - completely forgot about that to be honest as it's not something I use.

    About the quotes... the reason I don't like wrapping the entire thing in quotes or apostrophes is because it means if I want to use a Lua variable instead of typing in a specific name that I have to break the quote - in a manner of speaking.
    anim = "blink" -- an example Lua variable
    
    startAnimation("game.CurrentCharacter.CharacterCurrentOutfit.OutfitCharacterAnimations[" .. anim .. "]")

    It's ugly & can end up getting a little confusing to look at if you need to enter multiple variables or insert a VS value/condition.

    Imperátor

    7285 Posts

  • #16, z AlexFriday, 17. March 2017, 22:17 hodinky 8 years ago
    the next one that I thought made sense (and also was suggested by @sebastian and @alex if I didn't get it wrong) doesn't work: startAnimation("Characters[char1].CurrentOutfit.CharacterAnimations[anim1]",true) Seems I have to reference it as CharacterCurrentOutfit and not as CurrentOutfit, and same with OutiftCharacterAnimations instead of CharacterAnimations. Any idea why this is happening? Does this have anything to do with the parentheses being outside the path? Perhaps these startAnimation/stopAnimation don't work with shorthands?

    The difference exists when a string is used as a command parameter to find a visobject. In this case the complete field name is needed. e.g. only
    startAnimation("Characters[char1].CharacterCurrentOutfit.OutfitCharacterAnimations[anim1]",true)

    will work. When you get the visobject yourself you can use the shorthand names, e.g.
    local anim = Characters[char1].CurrentOutfit.CharacterAnimations[anim1]
    startAnimation(anim, true)


    from a user perspective this does not really make sense. Internally the different access methods have different implementations, that's why it's happening. This should be fixed for the final release.

    Čestný člen

    378 Posts

  • #17, z afrlmeFriday, 17. March 2017, 22:26 hodinky 8 years ago
    @ Alex: aye mate, it's a bit confusing, but nothing that can't be solved by testing out a few variations of the data structure VisObj names yourself. I mostly type out the fullname minus the "v" bit myself as I know there's less chance of returning an error, though I sometimes use shorter names on certain things like Values["name"].Int or .String. Conditions only seem to return correctly if you use .ConditionValue - what would have been nicer is .Cond, but having to type a few extra characters isn't much of an issue to me as I can type quite a lot in a short space of time anyway. wink

    Imperátor

    7285 Posts

  • #18, z sebastianMonday, 20. March 2017, 07:54 hodinky 8 years ago
    all in all its doable if you got yourself into the vast fields of the datastructure and its (sometimes confusing) methods smile 

    The greatest would be to have some autocomplete context menu popping up when typing lua which makes suggestions, etc like in modern IDEs smile 

    Kapitán

    2346 Posts

  • #19, z afrlmeMonday, 20. March 2017, 12:52 hodinky 8 years ago
    all in all its doable if you got yourself into the vast fields of the datastructure and its (sometimes confusing) methods smile 

    The greatest would be to have some autocomplete context menu popping up when typing lua which makes suggestions, etc like in modern IDEs smile 
    Aye mate that's something we would all like to see implemented. Simon said it's difficult to implement & is a lot of work - hopefully he will manage to sort it out someday. smile

    Imperátor

    7285 Posts