1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved split String at "\n"

Discussion in 'Skript' started by Legora, Feb 5, 2020.

Thread Status:
Not open for further replies.
  1. Legora

    Legora Member

    Joined:
    Feb 5, 2020
    Messages:
    4
    Likes Received:
    0
    Hello !

    TLDR: I want to split text "variable \n variable \n variable" on each "\n" and turn "variable" into an element of a list.

    After looking in java code, docs and other horrible things i'm in front of this little easy problem but i just can't find the right exact way to write it.

    So i have a huge string in this form : "variable \n variable \n variable"

    I want to get them into a list (named "{%player%.quests.list::*}" )

    Objective is to loop this list like this and setup a gui with it :
    Code (Text):
    1. loop {%player%.quests.list::*}:
    2.     set {quest} to loop-value
    3.     format gui slot { i } of player with book named "%{quest}%"
    I just can't make the "split" function works for some reason. Probably because it's a \n. Works fine on letters.



    Bonus : Is there a type of loop in skript that will make me win some time and increment a number by itself (To know how many loop i did before) or am i doing right by using my own variable. ( i in this exemple)

    Thanks !
    Hope my english isn't terrible.
    New on this forum and not sure how i'm supposed to ask for help?
     
    #1 Legora, Feb 5, 2020
    Last edited: Feb 5, 2020
  2. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,501
    Likes Received:
    108
    Medals:
    Is this solved? You marked it as such, but since you said you're new here, I'm not sure if you meant to.
    For your issue, Skript doesn't currently have a way to get a newline character, but there are some addons that can provide that. For example: SkQuery, SkUtilities (number 9) or skript-mirror.
    Bonus: you can use `loop {_number} times:`, and the expression `loop-number` will have the current iteration (if you want to use this for list variables with numerical indices, something like `loop size of {_list::*}:` will be useful).
    PS: I also recommend using local variables.
     
  3. Legora

    Legora Member

    Joined:
    Feb 5, 2020
    Messages:
    4
    Likes Received:
    0
    I was building my own GUI for "quests" but they actually sell a java GUI as un upgrade for 3$.
    I lost too much time searching how to do it. Then i though i found it when i found the keyword "split" (did multiple edit of this post each time i found new information xD) but then split didn't work well so i just forfaited.

    When i split the string "hello \n hello" it's working perfectly. Not when i split my variable.
    Thx for your answer, i'll do without the code ^^'
    local so they get deleted after the operation ?
     
  4. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,501
    Likes Received:
    108
    Medals:
    Local variables will be deleted after the trigger ends
     
Thread Status:
Not open for further replies.

Share This Page

Loading...