assurance-tunnel
assurance-tunnel
assurance-tunnel
assurance-tunnel

Use Javascript to select a line of Text



  • @dusx

    Brilliant, Ryan, that did the trick.

    Thanks!


  • Tech Staff

    Performance Note: It may be preferred to load the text file once before the Main function (requires moving just the read() line to the top of the script).
    This would stop the Javascript from issuing a read() File command everytime a line is requested.
    This might be important for large files.
    It will also cause refreshing the text only to occur on enterscene.



  • There are two scenes in this file, having to do with the text. Please have a look.

    https://www.dropbox.com/sh/2gw...

    --8


  • Tech Staff

    @eight
    I took a look, it seems you are using a slight variation and its working well for you.



  • I have a list of numbers in the Text actor. Sometimes Javascript does not output the correct number. I think it may be related to editing the Text, but I made sure the Javascript input is updated.



  • Hello Guys,

    I liked the Java Script solution a lot and wanted to modify it a bit.

    I would like to split the text lines only at two or more line breaks or along empty lines.

    I already tried a lot of combinations found at other Scripting forums like txt.split("\n\n"), txt.split("\n{2}"), txt.split("\\n\\n") and others. All of those solutions gave me errors while it worked for other people.

    Is it maybe a limitation of the Java Version Izzy is using?

    Does any of you maybe have a solution for this?


  • Beta Platinum

    Hi there @DillTheKraut,


    Any reason why you prefer the JavaScript option ? The Data Array actor has support for Text files since Izzy 2.6. Really nice actor that I use a lot for external file communication :)



  • @juriaan

    Yes, there is a reason. I try to read data from a pre defined text file. Named .edl files, containing cue data stretched sometimes over two lines, some times only one.

    As the data array needs specifically defined separation and works by single line only. It doesn't realy help.


  • Beta Platinum

    Okay, could you share the file that you wish to read. So that we can give you hand finding the right  way ;)



  • @juriaan

    I will, but I'm on not at my computer at the moment.

    But I as well would like to understand if the way I tried should be right, or if there are differences between java versions. But maybe there is something else wrong.


  • Tech Staff

    @dillthekraut

    It's not any difference between Javascript versions. It is likely that your text file is using additional line breaks.

    Opening it in a text editor like notepad++ will allow you to turn on viewing of invisible characters. Then you can edit the JS code to suite.

    It will likely be something like:  txt.split("\n\r")



  • @dusx Thanks, though I was sure to have tried it already. Strange enough, I had following experience:

    As you see in the picture, notepad++ is showing all breaks are equally CR/LF. But in the Java actor single \n worked as well as single \r. But giving me every single line, including empty ones as separate Array Items.

    I thought to have tried \n\r with the same result (but probably did \r\n instead of \n\r). While trying it again after your post, it now gives me the exactly wanted result, filling the array items with combined Data lines ignoring empty ones. Interestingly it seems to keeps the break between the data lines. See the results in the pictures...

    Honestly I don't really understand, what's happening here!

    ----


  • Tech Staff

    @dillthekraut

    OK, so.
    NotePad++ is showing CR LF, as the document end of line.
    This matches \r\n ( \r = Carriage Return, \n = Line Feed )

    reference: https://en.wikipedia.org/wiki/...

    So: txt.split("\r\n") should match that every end of line (but splitting on this will not remove any trailing sets from doubles)

    Now if you want to split the text only one DOUBLE breaks... you are looking at CR LF CR LF

    So try: txt.split("\r\n\r\n")



  • @dusx thank you! I guess I just switched \r with \n bevor. And now I know what's happening in the different cases and why ("\n\r") is doing the Job kind as well.

    In between (.../) shows the match of regex and therefore the position of the split:

    ("\r\n\r\n") =
    Line one text 'CR LF'
    line two text (CR LF
    CR LF/)
    third line of text

    ("\r\n") =
    Line one text (CR LF/)
    line two text (CR LF/)
    (CR LF/)
    third line of text

    ("\n\r") = 
    Line one text 'CR LF'
    line two text 'CR' (LF
    CR/)
    'LF'
    third line of text