[LUA] match pattern issue (aka wait for action to be finished)

  • #10, z afrlmeSunday, 18. September 2016, 12:58 hodinky 8 years ago
    This is where the @ symbol comes into play! wink

    & ok dokie.

    Imperátor

    7285 Posts


  • #11, z sebastianSunday, 18. September 2016, 22:28 hodinky 8 years ago
    before i am composing my concept into a sexy smexy e-mail id like to know what the best "format" for a file would be to read from.
    Best would be some kind of yaml for me, but i dont know if a can iterate through the entries.

    For example a file would contain this:
    dialog_part_1
    	text: "some cool text"											
    	action: "dialog_part_action_1"
    	
    dialog_part_2
    	text: "this could be also a text about some stuff"
    	action: "dialog_part_action_2"
    (...)
    


    The given string from a function would be "dialog_part_1" (or any other unique string in this file)

    I now want to search for "dialog_part_1" and get its "text" and "action" entries.
    grab it and create a table(!) out of it.

    This table didn't exist before because
    a) we don't know how much dialog parts could be in the current dialog. So creating it when needed would be great
    b) the name of the table is dynamically created by the given string.

    In the end i want to have this extracted when searching from dialog_part_1:

    local dialog_part_1 = {
    	text = "some cool text",
    	action = "dialog_part_action_1",
    }
    


    Any ideas how to format and search for / grab the "sub entries" and create a table out of it?

    Kapitán

    2346 Posts

  • #12, z afrlmeSunday, 18. September 2016, 22:39 hodinky 8 years ago
    Lua script does have search, split & match operators, but I've not used them all that much. I used gsub if I remember correctly for my playtime counter.

    I know that Daedalic have done extensive table scripts that use the match & split operators for quite a number of things.

    You are talking about creating a table from externally loaded files? Why not create them as tables in the files?

    As for the format: .txt, .ini or .lua will work fine. I recommend .lua if you just want to store data to be retrieved later on. Quick note though... I recently did a bit of freelance work on custom dialog display system for an upcoming visual novel / myst-like sci-fi game & the windows build read the external files without an issue, but for the mac build we ended up having to directly add the tables into the script section of the editor as they refused to load - unless paths work differently on the mac? I included the folder containing the tables in the project root folder, just as they were in the ved root folder, but they wouldn't load & as a result the demo ended up getting stuck at the intro after new game because it had no data to read from.

    Imperátor

    7285 Posts

  • #13, z sebastianSunday, 18. September 2016, 23:25 hodinky 8 years ago
    i've used split lately for my savegame system.
    The thing i want to achieve later is to have __easy__ files to "script" with.
    No bloated table parts, etc. So the files i want to deal with should be as simple as possible...

    The problem here is that (regarding to my example in the previous post)
    text = and action = appear more than one time in the file. They only have a different parent (the name of the later table).

    So i need some kind of differentiation where i need a bit of lua magic help smile



    A further question: The external files i use for this... are they packed with the game later or are they also freely readable (and manipulatable) by the later user?
    what did daedalic do with such files?

    Kapitán

    2346 Posts

  • #14, z afrlmeMonday, 19. September 2016, 01:16 hodinky 8 years ago
    Daedalic included their lipsync tables as lua files within the game folder. You have to manually copy them into your exported games folder with the same pathing you used for the ved project.

    You can actually make tables nice & neat...
    dialog_001 =
    {
     { txt = "some cool text", act = "dialog_part_action_1" }, 
     { txt = "this could be also a text about some stuff", act = "dialog_part_action_2" }
    }
    

    You would be able to access data from the example above like so...
    Values["temp_displaytext"].String = dialog_001[1].txt
    startAction(Actions[ dialog_001[1].act ])
    

    Technically you don't even need to bother with naming the dialogs. You could have a main table & just wrap each of them in double { like {{so}}, though it would be a lot more complicated to keep track of what's what.

    Imperátor

    7285 Posts

  • #15, z sebastianMonday, 19. September 2016, 01:35 hodinky 8 years ago
    the idea is to name each dialog part individually so that i can refer to them later (when calling the next dialog). Much easer to name things here instead of using 0,1,2,etc and you dont know what is what or rearrange the order of some entries inside the file.

    But i guess i have to use normal lua files then... with all the {} and stuff :p

    Am i also able to read the content of a lua script from inside the editor (not an action oart, but the scriot list) ? Would be a lot more secure to have it inside the project itself

    Kapitán

    2346 Posts

  • #16, z afrlmeMonday, 19. September 2016, 01:45 hodinky 8 years ago
    What I tend to do is create my tables / scripts inside of Sublime text, then import then copy/paste them into the scripting section of VS as either definition or execution type scripts once I'm happy with them.

    Yes it's more secure if you include them inside of the editor itself.

    Quick note: because you can change any variable into any variable type, you could create a unique script per dialog conversation as a execute script type & even use the same names, which would overwrite the old variables when you load the new table script. In the script you could include the total value of dialog part entries inside of a variable to make sure you only grab the correct ones from the tables. Also you can use unique names for table entries too, though it's much easier to use index values or let it generate index values as you can iterate through tables with the for loop.

    P.S: in regards to formatting it would have to in Lua script or even possibly in C, to be able to actually be able to use it. Ideally I suppose xml or something like that would be more desireable. Straight up text would most likely just return an error if you tried to load it into the game, though you could probably get away with reading said files like you do with Lua & using a mixture of the gsub, match & split operators to convert data to tables, but that would probably be slow compared to already having them stored as tables.

    Imperátor

    7285 Posts

  • #17, z sebastianMonday, 19. September 2016, 01:58 hodinky 8 years ago

    use the same names, which would overwrite the old variables when you load the new table script. In the script you could include the total value of dialog part entries inside of a variable to make sure you only grab the correct ones from the tables.

    thats kind of what i try to do (a bit different) .
    What i have right now is a static group of local tables which get loaded into a dialog_parts table and display their entries as object text + working arrow up/down to display the rest of the entries.

    Whats left is the dynamic creation of these (for now static) tables out of a file or VS editor script and i have my proof of concept wink
    Cool side effect if i use the VS editor for these scripts itself: I don't have to check for the file and read it...
    I have to get the scripts content, split it up and extract the neccessary lines... kind of...

    Kapitán

    2346 Posts

  • #18, z afrlmeMonday, 19. September 2016, 12:06 hodinky 8 years ago
    Sorry mate I'm having a hard time trying to grasp your idea in my head with text alone. Sometimes I can & sometimes it just makes my brain hurt. This time it's the latter.

    Maybe I'll be able to make more sense out of your email (or ved file & resources - if you decide to send me them).

    Imperátor

    7285 Posts

  • #19, z sebastianMonday, 19. September 2016, 12:33 hodinky 8 years ago
    ill send an email soon. Just have to clear up my thoughts, too razz
    Its very hard for me to describe it even in (english) sentences so i will try to create some kind of flow chart

    Kapitán

    2346 Posts

  • #20, z sebastianThursday, 22. September 2016, 22:58 hodinky 8 years ago
    Seems that i need a bit more time to think about the system. But I resolved a big issue in my concept which made it possible for me to rebuild the whole construct (on paper). Should theoretically work now.
    I will try to script it first by myself and if i need help i will notify ^^

    By the way : Do you have any experience with string.gmatch functions? I need to match the < b r / > (had to place a space between because these chars get removed by the forum) inside the ScriptScript from the DataStructure but it seems that
    string.gmatch(script_string, '([^
    ]+)') 
    

    will match but also sub parts of it...
    (script_string by the way is the content of a script inside of Visionaire)

    Its seems that my Pattern
    ([^
    ]+)
    
    is only for matching one single character because ([^$]+) works to match the character "$"...

    Kapitán

    2346 Posts