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

  • #1, by F_KalWednesday, 15. March 2017, 05:53 8 years ago
    I have a difficult time scripting, mainly because I am having difficulty understanding how to get the information I need out of the documentation - I would be much obliged if somebody could put me on the right track and clarify a few things for me.

    1) I've found 3 pages (Object Model,Player Commands,Data Structure) in the documentation that seem to be of interest - Am I missing some additional pages?
    2) I understand there is a shorthand mode that works for some object calls but doesn't work for other. Is there some list with the available shorthands?
    3)I was reading the startAnimation documentation where it gives the following example:

    startAnimation("Scenes[scene_name].SceneObjects[object_name].ObjectAnimations[animation_name]")
    In my case, I am trying to reference a particular standing animation that belongs to a particular outfit/character. I tried "decoding" the Data_Structure wiki page and assumed there might be a table CharacterLinks[] but CharacterLinks["char_name"].CurrentOutfit["outfit_name"].CharacterAnimations["anim_name"] isn't right... What did I get wrong? How would I properly reference it - better yet, how would I properly go about reading the documentation to find this information out by myself without all the guesswork?
    4) I see in various scripts an object array called ActiveAnimations[] - where would I find that in the documentation? I can only find the ActiveAnimation table/field in the Data Structure wiki - but where did ActiveAnimations (plural) come from?
    5) How do I know which properties/methods in the Data Structure wiki page are read only and which are read/write?
    6) How do I know the proper syntax to set them? Are they all set using the equals (=) operator? Or do some of them need the parameters in parentheses? 

    I'm so sorry for the long post; brief pointings are very welcome - no need for detailed answers (I can always come back asking more if I can't make use of the pointing)

    Thanks!


    Forum Fan

    107 Posts


  • #2, by sebastianWednesday, 15. March 2017, 09:13 8 years ago
    yes you found the relevamt sites in the wiki which refer to the usage if the visionaire objects with LUA. Of course there are some more additional pages - all under the " Scripting (Lua) " drop down menu in the wiki. 

    Im on the way to work right now so im not able to fully embrace each point. I will come back to this this evening then smile 

    Some short hints:

    your 
    CharacterLinks["char_name"].CurrentOutfit["outfit_name"].CharacterAnimations["anim_name"] was a good go. But there is no table "CharacterLinks" in visionaire as yiu already mentioned. 

    Roughly each headline in the data structure wiki page determines also a table name in visionaire which can be accessed by adding also an "s" behind it (Character - > Characters) . Not each table can be accesseed directly but mostly you can use this as a starting point. 

    Now that you have a table Characters you can do the following:

    startAnimation("Characters[char_name]") 

    okay... now thats not an animation.. we have to dig deeper. lets have a look at the characters table again and search for the outfit part in the character table:

    There is a field for the outfits which link to the CharacterOutfits. 

    You also could also try to go for  CharacterCurrentOutfit which links directly to the chars current outfit. So for now we use the outfit list and add it to our Lua line: 


    startAnimation("Characters[char_name].CharacterOutfits[outfit_name]") 


    (remember, we are accessing a new table which has possibly more entries and add an "s") 

    or

    startAnimation("Characters[char_name].CurrentOutfit") 

    i will go om with the first exanple here. 

    we are not done. lets see... where do we find the animation in the outfit table:


    OutfitCharacterAnimations looks like it links to animations... yay. Adding this in. 


    startAnimation("Characters[char_name].CharacterOutfits[outfit_name].CharacterAnimations[animation_name]") 

    recognize that i also left out some beginning word of the actual field. 
    (OutfitCharacterAnimations - > CharacterAnimations). Has something to do with the shorthand method. Not well documented though...  

    that should do the trick. This is the "safe" method because you referenced directly to the animation from a characters outfit and the possibility you named two animations the same in this outfit is not so big.

    What you could also do is:
    startAnimation("Animations[animation_name]") 

    This will do the same IF there is only one animation named like "animation_name" in the project.  If there are more animations with the same name it will probably start the animation the engine finds first in the project (not compulsory a character animation) . 

    So either name all animations different (which i would suggest anyway) and go fir my last mentioned script or you have to determine the animation more specific by addressing it like the above mentioned method.

    kind regards 
    Sebastian 

    Thread Captain

    2346 Posts

  • #3, by AlexWednesday, 15. March 2017, 09:28 8 years ago
    Hi,

    you're right, the scripting documentation is somewhat incomplete and not perfect. We are already working on improving it in the near future.

    1) that's basically it, plus some examples and tutorials

    3) CharacterLinks contains links to all characters (in the Characters table) that exists just for intern reasons, so every character object has a parent object (the game object). If you want to access a character you can directly reference the character table, e.g.
    Characters[Hero]

    further CurrentOutfit is a link to the current outfit, so no further name is needed. In your example that should be:
    Characters["char_name"].CurrentOutfit.CharacterAnimations["anim_name"]

    4) All table names are in plural, so when you access a table you have to use the plural name, e.g. Characters[Hero], Conditions[game_started], etc. that's probably also something that is not explicitly mentionend in the doc

    5) in the data structure documentation there is a column Scriptable, if it is checked you can write to this field. Of course you can theoretically write to every field but it is not guaranteed to work, e.g. there could be problems when the game is saved or the change is not immediately visible but only after the scene is changed.

    6) you can either use the setValue method of the visionaire object, e.g.
    Characters[Hero]:setValue(VCharacterActive, false)

    or you could also assign this directly
    Characters[Hero].Active = false

    the shorthand method was introduced in a later release, that's why most documentation uses the setValue method.

    Great Poster

    378 Posts

  • #4, by afrlmeWednesday, 15. March 2017, 11:43 8 years ago
    oh dear. Scripting section is about the only section in the wiki that is very nearly complete. There's more pages than those 3. Script index contains tons of already written scripts & examples.

    Scripting & Data Structure are the only 2 pages you really need, though player commands is useful providing you can wrap your head around the syntax examples (they gave me a headache, which is why I'd made a start on writing out easier to understand versions of player commands page on the script index page).

    In regards to shorthand; it's very hard to create documentation for because there's multiples ways in which you can write the VisObj data structure fields out, but in some cases you have to write out the full data structure name because of conflicting entries with same words/names in them - I can't think of any examples off the top of my head at the minute though sorry (just woken up recently).

    both this...
    game.CurrentCharacter.CharacterPosition = {x = 500, y = 500}

    & this...
    game.CurrentCharacter.Position = {x = 500, y = 500}

    are the same thing, though in some cases some shorthand methods will generate errors in the log file, so if that happens, it's probably best to use the full data structure field name if you see any errors associated with it.

    One thing I will tell you is that the names of any object/button/character, etc that you create in Visionaire Studio are case sensitive, so when you access them with Lua script, they have to be written exactly the same as you named them inside of the Visionaire Studio Editor. For example, if you named a character "Tom" then you need to write Tom; not tom, or ToM, or tOm, etc. It has to match perfectly or it will return an error.

    Final tip: if you work with multiple monitors, I highly recommend checking out snaketail. It's a really nice open source application for real time log monitoring. You can load in multiple txt/log files & it will display whatever is inside of the linked files as they are updated.

    Imperator

    7285 Posts

  • #5, by F_KalWednesday, 15. March 2017, 15:37 8 years ago
    wow @sebastian, @Alex and @AFRLme, thank you so much for helping me out - there is a wealth of information here! now that I'm well-awake, I'll read them properly and get back to you as soon as I assimilate your pointings (or some questions pops up)

    Thanks again!

    Forum Fan

    107 Posts

  • #6, by F_KalWednesday, 15. March 2017, 19:47 8 years ago
    thanks again guys, I finally feel that I get it now! 
    Actually the Data Structure wiki page is well written and easy to "decode" now that you explained to me how the names are constructed and change between shorthand and the full name!

    I'm much obliged!

    If you don't mind, here are a few more questions:
    1) in the scripting wiki page, it says

    Exported Constants:
    [...]
    all visionaire tables. These constants start with an e and then the plural table name. E.g. for the table Action the constant is eActions.

    what does this refer to? Is it the tables that we've been discussing here? Is this synomymous to Actions[]? Scenes[]? Animations[]? Characters[]? Does it mean that I could use eCharacters[Hero]:setValue(VCharacterActive, false) and eCharacters[Hero].Active = false?

    2) I found the following wiki page on google, but I can't find it via the menu system, could somebody point me how to find this in the menu?

    Again thank each and every one of you, I now feel much more confident with scripts!

    Forum Fan

    107 Posts

  • #7, by sebastianWednesday, 15. March 2017, 21:13 8 years ago
    thanks again guys, I finally feel that I get it now! 
    Actually the Data Structure wiki page is well written and easy to "decode" now that you explained to me how the names are constructed and change between shorthand and the full name!

    I'm much obliged!

    If you don't mind, here are a few more questions:
    1) in the scripting wiki page, it says

    Exported Constants:
    [...]
    all visionaire tables. These constants start with an e and then the plural table name. E.g. for the table Action the constant is eActions.

    what does this refer to? Is it the tables that we've been discussing here? Is this synomymous to Actions[]? Scenes[]? Animations[]? Characters[]? Does it mean that I could use eCharacters[Hero]:setValue(VCharacterActive, false) and eCharacters[Hero].Active = false?

    2) I found the following wiki page on google, but I can't find it via the menu system, could somebody point me how to find this in the menu?

    Again thank each and every one of you, I now feel much more confident with scripts!

    hehe... yea, thats another weird thing. In fact yes... All tables begin with an e. When you press ctrl+e or cmd+e in visionaire studio, it opens up the so called "explorer" which breaks down all your things you did in your project to its corresponding tables.

    When using Luascript you don't need to write the "e" in front of them... I guess it gets added internally either way.
    Maybe a dev member can bring some light here into the dark why this "e" was introduced and for what it stands for^^ I'm curious razz

    Don't know why the page you found is not linked anywhere. I guess it was discontinued by the creator because it only contains two character table examples. Maybe AFRLme knows it. He is the main maintainer of the wiki. 

    *summon afrlme* *rain dance* *wololo*

    Thread Captain

    2346 Posts

  • #8, by F_KalWednesday, 15. March 2017, 22:31 8 years ago
    wow, the explorer! Now that was another oversight on my part; I had totally forgotten about it! 
    Thanks again @sebastian! 

    Forum Fan

    107 Posts

  • #9, by afrlmeWednesday, 15. March 2017, 22:50 8 years ago
    @ Sebastian: based on the history of the wiki page & the way it's written in general, I would say I wrote it. I guess I planned on creating in-depth explanations & examples of each of the data structure fields, but I probably realized what a huge task that would be to take on considering the data strucure is prone to change each time Visionaire Studio gets an update. To be honest I don't remember creating or writing that page at all, but according to the history the author is AFRLme, which is me... I guess.

    P.S: I have no plans at all to continue work on that page > ever. Maybe I should just delete it?

    Imperator

    7285 Posts

  • #10, by AlexWednesday, 15. March 2017, 23:29 8 years ago

    Exported Constants:
    [...]
    all visionaire tables. These constants start with an e and then the plural table name. E.g. for the table Action the constant is eActions.

    what does this refer to? Is it the tables that we've been discussing here? Is this synomymous to Actions[]? Scenes[]? Animations[]? Characters[]? Does it mean that I could use eCharacters[Hero]:setValue(VCharacterActive, false) and eCharacters[Hero].Active = false?


    The e stands for enum(eration), the value of an enum is always an integer. So eCharacters has nothing to do with the table Characters itself.  For example you could use the enum to check the table of an object, e.g.

    local obj = game.CurrentObject
    if obj:getId().tableId == eObjects and obj.ObjectIsItem then
        print(obj:getName() .. ' is an interface item')
    end

    Great Poster

    378 Posts

  • #11, by sebastianThursday, 16. March 2017, 07:33 8 years ago
    ah ok. my mistake smile 


    Thread Captain

    2346 Posts