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

  • #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


  • #21, z afrlmeThursday, 22. September 2016, 23:55 hodinky 8 years ago
    I tried forcing a br tag into a values string & then calling that value inside of a display text & it seemed to ignore the br tag - or more to the point it decided to print that too. I think though that you could probably use the new Lua draw feature to display text wherever & however you like, but I've not tried using it yet, so no idea how that works.

    As for your gmatch thing, I think you have to iterate through each character, though you could use one of the other sub functions maybe?

    string.find should do the trick though, then you should be able to use string.gsub to replace or edit all instances as needed.
    txt = "some text"
    
    if string.find(txt, "
    ") then string.gsub(txt, "(
    )", "") end -- delete all instances of br tag
    

    Not sure if that's correct, but I think you get the idea. Really should google for Lua stuff mate. Loads of websites & blogs out there with information on all the different operators.

    http://lua-users.org/wiki/PatternsTutorial
    http://lua-users.org/wiki/StringLibraryTutorial

    Imperátor

    7285 Posts

  • #22, z sebastianFriday, 23. September 2016, 07:41 hodinky 8 years ago
    thanks smile
    but i dont need to remove it like that. I have the string read out of a ScriptScript from visionaire. Each new line has a "br" tag at the end.
    I want to put every line into a separate table field. The "br" is the separator and should get automatically removed anyway.

    The slash of the br has to be escaped by an %... maybe thats because my pattern is not working correctly.

    To make it more clear. Thats may string:
     
    entry1
    entry2
    entry3
    entry4
    

    and i want to do/use this
     
    local parts = {} 
    for w in string.gmatch(stringname, '([^
    ] +)')  do table.insert(parts,w) end
    

    after that I should have the following table:
    parts = {
    [1] = "entry1"
    [2] = "entry2"
    [3] = "entry3"
    [4] = "entry4"
    } 
    

    but it gets also split after the" r" from entry... So the matching pattern is wrong...

    Kapitán

    2346 Posts

  • #23, z afrlmeFriday, 23. September 2016, 18:07 hodinky 8 years ago
    Here you go mate...
    local str = 'the dog chases the cat!
    while the cat chases the mouse!
    and the mouse goes squeak! squeak! squeak! all the way to its hidey-hole.' -- the string
    local parts = {} -- create empty table
    
    -- * return everything that doesn't equal 
     * --
    for word in string.gmatch(str, '([^
    ]+)') do
     table.insert(parts, word) -- insert words into table
    end
    
    for i = 1, #parts do print(parts[i]) end -- return the table entries
    

    Imperátor

    7285 Posts

  • #24, z sebastianFriday, 23. September 2016, 18:19 hodinky 8 years ago
    really? was it only the slash instead of percent inside the pattern?
    But why? Thought the escape char in lua was %... thats weird. I will try as soon as im home (just on my way)

    I feel more dumb than usual now xD

    thanks so far smile


    Kapitán

    2346 Posts

  • #25, z sebastianFriday, 23. September 2016, 18:21 hodinky 8 years ago
    i think i get it. To escape some chars you have to write it twice. The % instead is a indicator for slecific pattern stuff... kind of

    Kapitán

    2346 Posts

  • #26, z afrlmeFriday, 23. September 2016, 19:43 hodinky 8 years ago
    \ is a command thing, but as far as I know / is not, so not sure why it needed 2 of them to work. Check out the \ commands near the top of this page: https://www.lua.org/pil/2.4.html - \n for example can be used to drop to a new line when writing to an external txt, lua or ini file, etc. While iterating through some strings, it will automatically drop to a new line each time \n is encountered (see my message below about using external files).

    It works though, you can see the log results in this screenshot here: https://gyazo.com/75586bb3b27944e463f1b120d97a78db

    Quick note: don't add any white space " " between the last word, the br tag & the next word as it will include those in the table. I ended up with something like this...
    cat
     dog
     mouse
    

    ... after the first string I tried. You could strip out the white space obviously but you would have to be very selective that it doesn't strip out the wrong bits.

    Something you could consider doing is writing them into external files as you could replace the
    tags with \n & each time you write to the file it will automatically drop a line each time it encounters \n.

    Imperátor

    7285 Posts

  • #27, z sebastianFriday, 23. September 2016, 21:20 hodinky 8 years ago
    thanks so much. works =)
    Im now at a point where i have to implement two more things:
    a)continue the dialog if there is a "sub tree" of choosable dialogs
    b)if there is only one dialog part left, auto choose it directly (and don't display it)

    Kapitán

    2346 Posts

  • #28, z afrlmeFriday, 23. September 2016, 21:25 hodinky 8 years ago
    You can probably do that by checking against the table total...

    P.S: your system is giving me an headache. I have no idea what you are trying to achieve as I can't visualize it in my head. I guess some diagrams would be nice right about now or access to what you are doing so I can see for myself.

    Imperátor

    7285 Posts

  • #29, z sebastianFriday, 23. September 2016, 22:54 hodinky 8 years ago
    yeah pretty straight forward right now. i managed b) already and a) is just starting a new dialog with a saved argument from the prior dialog (to continue)

    When this is ready i will make some kind of flow chart

    Kapitán

    2346 Posts

  • #30, z afrlmeSaturday, 24. September 2016, 01:40 hodinky 8 years ago
    ok mate, looking forward to seeing what you've cooked up. Hopefully the flowchart will make more sense to me. smile

    Imperátor

    7285 Posts