Solved Add book pages based on line count

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Farid

Active Member
Feb 5, 2017
179
11
18
23
I'm trying to create a book, and write in the book based on a .txt file. I want each page have 13 lines, and after 13 lines it should create a new page. I've tried many math algorithm, but as you know, I suck at math lmao.


https://i.gyazo.com/f7b59310eeb4b39c20a76162908942bc.png (Notepad .txt)
https://i.gyazo.com/aaf49c10685d64cf3b2d7e3f25b46d89.png (Book in-game, each line is a new page.)
https://i.gyazo.com/701111fa72716a32bb30589fc55b1f04.png (Code)


I tried add a page with every 13 lines or more, but it didn't quite go well.
 
The issue is that each "text component" appears to be considered an entire new line. In minecraft JSON, the limiter "\n" is used to create a new line. Joining 13 lines together in a single value variable, split by "\n", and THEN add that as a new text component. Something like this:
code_language.skript:
loop {_components::*}:
    if {_line} is not set:
        set {_line} to 1
        set {_component} to loop-value
    else:
        add 1 to {_line}
        set {_component} to "%{_component}%\n%loop-value%"
    {_line} = 13
    \\\##
    add component to book etc
 
The issue is that each "text component" appears to be considered an entire new line. In minecraft JSON, the limiter "\n" is used to create a new line. Joining 13 lines together in a single value variable, split by "\n", and THEN add that as a new text component. Something like this:
code_language.skript:
loop {_components::*}:
    if {_line} is not set:
        set {_line} to 1
        set {_component} to loop-value
    else:
        add 1 to {_line}
        set {_component} to "%{_component}%\n%loop-value%"
    {_line} = 13
    \\\##
    add component to book etc
I fixed the entering part, my main issue is the algorithm for adding a page every 13 lines, and continuing in based on test.txt
 
Try this:
code_language.skript:
loop {_component::*}:
    set {_i} to loop-index parsed as a number
    add loop-value to {_list::*}
    if mod({_i}, 13) = 0:
        loop {_list::*}:
            add text component loop-value-2 to book {_book}
        delete {_list::*}
 
  • Like
Reactions: Farid
Try this:
code_language.skript:
loop {_component::*}:
    set {_i} to loop-index parsed as a number
    add loop-value to {_list::*}
    if mod({_i}, 13) = 0:
        loop {_list::*}:
            add text component loop-value-2 to book {_book}
        delete {_list::*}
13 pages, each page is next line.
 
Okay try this:
code_language.skript:
loop {_component::*}:
    set {_i} to loop-index parsed as a number
    add loop-value to {_list::*}
    if mod({_i}, 13) = 0:
        set {_txt} to ""
        loop {_list::*}:
            set {_txt} to "%{_txt}%%loop-value-2%"
        set {_c} to a new text component with {_txt}
        add text component {_c} to book {_book}
        delete {_list::*}
 
Okay try this:
code_language.skript:
loop {_component::*}:
    set {_i} to loop-index parsed as a number
    add loop-value to {_list::*}
    if mod({_i}, 13) = 0:
        set {_txt} to ""
        loop {_list::*}:
            set {_txt} to "%{_txt}%%loop-value-2%"
        set {_c} to a new text component with {_txt}
        add text component {_c} to book {_book}
        delete {_list::*}
Still nope, I'll figure it out thanks for the help!
 
Well what's the result of the code?
3300c0231c4a28e5bf5e9e05f2b4dba2.png

https://gyazo.com/3300c0231c4a28e5bf5e9e05f2b4dba2
 
I was having trouble adding pages, page 2 would have line 14, line 15, etc.
Okay can you send your current code in code brackets, not as an image so I can copy it?
 
Okay can you send your current code in code brackets, not as an image so I can copy it?
code_language.skript:
command /test:
    trigger:
        set {_lines} to skutilities line count of file "/plugins/test/test.txt"
        set {_book} to a new written book
        loop {_lines} times:
            set {_s} to skutilities line loop-number in file "/plugins/test/test.txt"
            set {_component::%loop-number%} to a new text component with "%colored {_s}%%nl%"
       
        set {_components} to ""
        loop {_component::*}:
            if (loop-index parsed as integer) <= 13:
                set {_components} to "%{_components}%%loop-value%"
        broadcast "%{_components}%"
       
        add text component {_components} to book {_book}  
        open book {_book} to player
 
Okay I made this and it worked for me:
code_language.skript:
command /test:
    trigger:
        set {_lines} to skutilities line count of file "/plugins/test/test.txt"
        set {_book} to a new written book
        loop {_lines} times:
            set {_s} to skutilities line loop-number in file "/plugins/test/test.txt"
            set {_component::%loop-number%} to a new text component with "%colored {_s}%%nl%"
        loop {_component::*}:
            set {_i} to loop-index parsed as a number
            add loop-value to {_list::*}
            if mod({_i}, 13) = 0:
                set {_txt} to ""
                loop {_list::*}:
                    set {_txt} to "%{_txt}%%loop-value-2%"
                set {_c} to a new text component with "%{_txt}%"
                add text component {_c} to book {_book}
                delete {_list::*}
        set {_s} to size of {_component::*}
        if mod({_s}, 13) != 0:
            set {_txt} to ""
            loop {_list::*}:
                set {_txt} to "%{_txt}%%loop-value%"
            set {_c} to a new text component with "%{_txt}%"
            add text component {_c} to book {_book}
        open book {_book} to player
 
Status
Not open for further replies.