Solved split String at "\n"

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

Legora

Member
Feb 5, 2020
4
0
0
25
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:
loop {%player%.quests.list::*}:
    set {quest} to loop-value
    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?
 
Last edited:
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:
loop {%player%.quests.list::*}:
    set {quest} to loop-value
    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?
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.
 
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 ?
 
Status
Not open for further replies.