Skript
Skript copied to clipboard
Implement Java 15 like multi line strings
Suggestion
In Java 21 you can define multiple line strings with three """
Skript could follow this formatting
set {_string} to """
<example>
Something
Another line
Another one
</example>
"""
set {_contents::*} to all of the xml tags "example" from {_string}
set page 1 of {_book} to """
&n&lWelcome To The Island!
Beware of the sharks!
There is treasure afoot, so go search and
dig up the goodies
"""
Why?
Since Java made this an official feature, it will become mainstream and the formatting will be adapted to this from Java over time.
Other
https://blogs.oracle.com/java/post/the-arrival-of-java-21 https://www.baeldung.com/java-multiline-string https://openjdk.org/jeps/430
Agreement
- [X] I have read the guidelines above and affirm I am following them with this suggestion.
I'm pretty strongly against this. I think, for one, it looks very bad in Skript code and can be confusing as to how far it should be indented, what indentation is part of the string and what isn't, and just plain isn't necessary. I think that it being part of java 21 isn't really any reason to add it to Skript, either. Especially since Skript has a history of having each line do something, like an entry or an effect/section.
It'll drastically help with long lines.
For example book pages;
the syntaxes have to be a huge line and you need to use %nl%
to add a line break.
set page 1 of {_book} to "&8&l----------------&r%nl% &5&lCapture &2&lThe &5&lFlag&r%nl%&8&l----------------&r%nl%%nl%&8Goal of the game is to capture the enemy flag and bring it to your team's base.%nl%%nl%%nl% &lContinued ->"
set page 2 of {_book} to "&8There will be a flag on the enemy team.%nl%&8Collecting the flag gives you slowness, and you cannot shoot paintballs.%nl%&8Dropping the collected flag allows you to shoot paintballs again.%nl%&8This is because if you're contested, you should have to fight for the flag carry."
set page 3 of {_book} to "&8When carrying the flag for your team, any damage dealt to you will cause the flag to drop."
set page 4 of {_book} to "&8The first team to &5&l%{ctf::winCaptures}% &r&8flag captures will be declared the winner.%nl%%nl%&8The winners of the event will be safe from elimination.%nl%%nl%&lGood luck and have fun!"
set slot 0 of {_player} to {_book}
It'll drastically help with long lines. For example book pages; the syntaxes have to be a huge line and you need to use
%nl%
to add a line break.
I think that's probably the one niche place it would help, but I'd rather see that problem solved by the page syntax being set to a list of strings, like lore, rather than a multiline string.
I would consider this as mostly duplicate of #6086 for the multi-line feature which I personally against it for various reasons.
Ignoring any difficulties in implementation, Java's text blocks are quite unfriendly to use. To begin with, they don't allow any kind of input or easy interpolation, so they're really only useful for giant walls of text.
It's quite ambiguous what is and isn't part of the text.
// the first line/newline isn't part of the text
// the text starts at the beginning of `hello`
String string = """
hello
""" // but this last newline IS part of the text, so it isn't symmetric
Comments also don't work in a text block, because everything inside is literal text.
// this is a comment
String string = """
// this is not a comment :( this is text :(
/* this is not a comment either */
hello this is text""" // now this is a comment again
Indentation is a bit painful, and seems to be based on whichever of the lines (except the first) starts first.
String string = """
| <- indentation starts here
so this line will start with whitespace"""
But it can also include the terminating line,
String string = """
this line will start with whitespace
so will this line
""" // because oops indentation started here at caret 0
which will be extra problematic in Skript because people won't know where anything starts and ends and won't know why they have/don't have the indentation they wanted.
I like the idea of supporting this, but I also agree that the triple quotes syntax wouldn't be very friendly. I'm not necessarily proposing this, but an old addon of mine (WebAddon) had a section for this. It was something like:
on script load:
multiline string:
hello
world! # This line would have 2 spaces of indentation
broadcast last multiline string
The syntax on this would definitely need some polishing but I would be interested to see what you guys think of this variation of the idea. We could even remove the whole last multiline string
expression and do something like set {_hello} to a multiline string:
.
I definitely think that's better, but I'd leave it for an addon to support if a user really wants it. It's just too big a departure from the expectations that Skript currently has about what a line of code should do, so it's a pretty severe impact to code readability, which I'm not a big fan of.
+1