How to create pages from song strophes

Hello all. So, may be I am stupid, or really tired, but... I need a help.
I have a text with strophes ... like a this :

  1. text first is here
    2.text second is here
    3.text third is here ... and so on.
    I need extract this strophes to separate pages. If I click/or step with button increment I will have displayed only text from 1. strophe.
    Until today I have this solution :
out2 = flow.get("clean_song"); // cleaned text from XML phrases
var tam_msg = out2.length; // lenght of full text - all strophes
for (var k = 1; k <= 16; k++) { // maximum 16 strophes in each song
    m=k+1;
for (var i = 0; i < tam_msg; i++) {// scan text for k defined numbers
    if (i < 10) { // compare if number is less than 10 or no
        extr_out2 = out2[i]; // get only 1 sign to compare
    }else{
        extr_out2 = out2[i] + out2[i+1]; // get 2 signs to compare
    }
    if (extr_out2 == k) {
        l = i;
    }
    if (extr_out2 == m) {
    g=i-l;    
    }
    
    if (k==1){
    msgList[k] = out2.substr(0, g);     
    }else{
    msgList[k] = out2.substr(l, g); 
    }
      
}

But there is a mistake. Because, if I have counted strophes over number 9, first strophe is not possible to view. It can displays only number 1 and no other text from 1 strophe.

Thanks for all help. You can also may to change whole script If you want.

Anybody to help me ? No ideas ?

Can you post an actual example message that goes into this function.

Can you provide an example of what should be sent out of the function for the above actual example message

This will help us interpret what you are trying to achieve

Actual message is in my first original post. Is the same format f.e. :

1.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean et est a dui semper facilisis. Pellentesque placerat elit a nunc. Nullam tortor odio, rutrum quis, egestas ut, posuere sed, felis. 
2.Vestibulum placerat feugiat nisl. Suspendisse lacinia, odio non feugiat vestibulum, sem erat blandit metus, ac nonummy magna odio pharetra felis. Vivamus vehicula velit non metus faucibus auctor. 
3.Nam sed augue. Donec orci. Cras eget diam et dolor dapibus sollicitudin. In lacinia, tellus vitae laoreet ultrices, lectus ligula dictum dui, eget condimentum velit dui vitae ante. Nulla nonummy augue nec pede. Pellentesque ut nulla. Donec at libero. 
4.Pellentesque at nisl ac nisi fermentum viverra. Praesent odio. Phasellus tincidunt diam ut ipsum. Donec eget est.

And what do you expect the output of the function to be based on that input?

This principe will be used for song reader. I need separate it to arrays and next by up/down buttons it can be selectable for the bigger display reading single strophes. F.e. for stages.

ok, your description is very minimal and I dont have the time for too much back & forth so here is a demo of my "best guess" of what you want.

chrome_8YK7c8YVXe

Demo Flow (use CTRL-I to import)

[{"id":"98d7c782f6c10e70","type":"inject","z":"50f66a9ef4a1b0b7","name":"Load Lorem ipsum","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Lorem ipsum","payload":"true","payloadType":"bool","x":685,"y":200,"wires":[["ddfa5e054ed6e258"]],"l":false},{"id":"ddfa5e054ed6e258","type":"template","z":"50f66a9ef4a1b0b7","name":"Lorem ipsum","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean et est a dui semper facilisis. Pellentesque placerat elit a nunc. Nullam tortor odio, rutrum quis, egestas ut, posuere sed, felis. \n2.Vestibulum placerat feugiat nisl. Suspendisse lacinia, odio non feugiat vestibulum, sem erat blandit metus, ac nonummy magna odio pharetra felis. Vivamus vehicula velit non metus faucibus auctor. \n3.Nam sed augue. Donec orci. Cras eget diam et dolor dapibus sollicitudin. In lacinia, tellus vitae laoreet ultrices, lectus ligula dictum dui, eget condimentum velit dui vitae ante. Nulla nonummy augue nec pede. Pellentesque ut nulla. Donec at libero. \n4.Pellentesque at nisl ac nisi fermentum viverra. Praesent odio. Phasellus tincidunt diam ut ipsum. Donec eget est.\n","output":"str","x":790,"y":200,"wires":[["f4653b15cc1447a9"]]},{"id":"3414e001a8e61ee9","type":"template","z":"50f66a9ef4a1b0b7","name":"The itsy bitsy spider","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The itsy bitsy spider climbed up the waterspout.\nDown came the rain and washed the spider out.\nOut came the sun and dried up all the rain\nAnd the itsy bitsy spider climbed up the spout again.","output":"str","x":820,"y":260,"wires":[["f4653b15cc1447a9"]]},{"id":"b42091bdc1bbdd9d","type":"inject","z":"50f66a9ef4a1b0b7","name":"Load The itsy bitsy spider","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"The itsy bitsy spider","payload":"true","payloadType":"bool","x":685,"y":260,"wires":[["3414e001a8e61ee9"]],"l":false},{"id":"f4653b15cc1447a9","type":"function","z":"50f66a9ef4a1b0b7","name":"Load Song","func":"const cleanLines = []\nconst lines = msg.payload.split('\\n')\n\nlines.forEach(function(e) {\n    const parts = /(\\d*)\\W*(.*)/.exec(e)\n    let line = parts[2]\n    if (typeof line === 'string') {\n        line = line.trim()\n        if (line && line.length > 0) {\n            cleanLines.push(line)\n        }\n    }\n})\n\nconst song = {\n    // internals\n    name: msg.topic,\n    _lines: [...cleanLines],\n    _lineCount: cleanLines.length,\n    _currentLineNo: 1,\n    // functions\n    nextLine() {\n        this.currentLineNo = this.currentLineNo + 1\n        return this.currentLineNo\n    },\n    prevLine () {\n        this.currentLineNo = this.currentLineNo - 1\n        return this.currentLineNo\n    },\n    // property getters / setters\n    get lines() { return this._lines },\n    get lineCount() { return this._lineCount },\n    get currentLine() { return this.lines[this.currentLineNo - 1] },\n    get currentLineNo() { return this._currentLineNo },\n    set currentLineNo(num) {\n        this._currentLineNo = num\n        if (this._currentLineNo < 1) {\n            this._currentLineNo = 1\n        } \n        if (this._currentLineNo > this.lineCount) {\n            this._currentLineNo = this.lineCount\n        }\n    }\n}\n\nmsg.payload = song\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":220,"wires":[["9d58dd71ed19aced","ae2a8716ac296151"]]},{"id":"9d58dd71ed19aced","type":"change","z":"50f66a9ef4a1b0b7","name":"","rules":[{"t":"set","p":"activeSong","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":220,"wires":[["56e18301e2ce53f4"]]},{"id":"ae2a8716ac296151","type":"debug","z":"50f66a9ef4a1b0b7","name":"debug 175","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":260,"wires":[]},{"id":"480a3e6e7a5d10b9","type":"ui_text","z":"50f66a9ef4a1b0b7","group":"6d262ebe1aa5cfbf","order":4,"width":"17","height":"1","name":"","label":"šŸŽµ","format":"{{msg.payload}}","layout":"row-left","className":"","x":1350,"y":480,"wires":[]},{"id":"45758b0b136ba300","type":"change","z":"50f66a9ef4a1b0b7","name":"get title","rules":[{"t":"set","p":"payload","pt":"msg","to":"activeSong.name","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":400,"wires":[["b61d077b0e35d2b4"]]},{"id":"c28a4242c47c462a","type":"ui_button","z":"50f66a9ef4a1b0b7","name":"","group":"6d262ebe1aa5cfbf","order":7,"width":"9","height":"1","passthru":false,"label":"Prev","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":690,"y":440,"wires":[["8fad65c32276de1f"]]},{"id":"7964da1bfe44ae9c","type":"ui_button","z":"50f66a9ef4a1b0b7","name":"","group":"6d262ebe1aa5cfbf","order":8,"width":"9","height":"1","passthru":false,"label":"Next","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":690,"y":480,"wires":[["abed403cc2d53333"]]},{"id":"8fad65c32276de1f","type":"function","z":"50f66a9ef4a1b0b7","name":"set prev line","func":"const song = global.get('activeSong')\n\nif (!song || song.lineCount <= 0) {\n    msg.payload = ''\n} else {\n    song.prevLine()\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":440,"wires":[["56e18301e2ce53f4"]]},{"id":"abed403cc2d53333","type":"function","z":"50f66a9ef4a1b0b7","name":"set next line","func":"const song = global.get('activeSong')\n\nif (!song || song.lineCount <= 0) {\n    msg.payload = ''\n} else {\n    song.nextLine()\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":480,"wires":[["56e18301e2ce53f4"]]},{"id":"040f703aa59229bc","type":"ui_ui_control","z":"50f66a9ef4a1b0b7","name":"on connect","events":"all","x":850,"y":400,"wires":[["56e18301e2ce53f4"]]},{"id":"b61d077b0e35d2b4","type":"ui_text","z":"50f66a9ef4a1b0b7","group":"6d262ebe1aa5cfbf","order":1,"width":"18","height":"1","name":"","label":"šŸŽ¼","format":"{{msg.payload}}","layout":"row-left","className":"","x":1350,"y":400,"wires":[]},{"id":"c7d9d2405a47bd63","type":"change","z":"50f66a9ef4a1b0b7","name":"get current line","rules":[{"t":"set","p":"payload","pt":"msg","to":"activeSong.currentLine","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":480,"wires":[["480a3e6e7a5d10b9"]]},{"id":"c504fad963af4719","type":"ui_text","z":"50f66a9ef4a1b0b7","group":"6d262ebe1aa5cfbf","order":3,"width":"1","height":"1","name":"","label":"#ļøāƒ£","format":"{{msg.payload}}","layout":"row-left","className":"","x":1350,"y":440,"wires":[]},{"id":"93bb21e8a19d50f5","type":"change","z":"50f66a9ef4a1b0b7","name":"get line number","rules":[{"t":"set","p":"payload","pt":"msg","to":"activeSong.currentLineNo","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":440,"wires":[["c504fad963af4719"]]},{"id":"56e18301e2ce53f4","type":"junction","z":"50f66a9ef4a1b0b7","x":1020,"y":460,"wires":[["45758b0b136ba300","c7d9d2405a47bd63","93bb21e8a19d50f5"]]},{"id":"6d262ebe1aa5cfbf","type":"ui_group","name":"Default","tab":"34f5e165d494f88b","order":1,"disp":false,"width":"18","collapse":false,"className":""},{"id":"34f5e165d494f88b","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Thanks a lot for your help. This works very well. At this moment I am working on dividing the long stanzas into parts possible to see on the 27" display from 20 meters for all people. Maximum will be 4 rows/or 80-85 signs on part of stanza and font size 170 Arial. So this is also a challenge. If you have any ideas, please help me. I think, will be resolved faster. You are better programmer than me.

Also for this can be used vertical arrow buttons f.e. on the left side to correct identify to slide stanzas down.

I am afraid I don't quite understand what you really want.

Perhaps if you provide a sketch (with annotations and layout hints) someone will show you how.

Otherwise, keep having a go yourself - you will get there (and learn more in the process)

OK, I try it by myself. Thanks a lot.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.