-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support string concatenation. #6576
Support string concatenation. #6576
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful 🎉 Let's hope it doesn't break anything we didn't think of
src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For string + string
should we treat an empty variable as an empty string? E.x. "some string" + {_none} = "some string"
src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/classes/data/DefaultOperations.java
Outdated
Show resolved
Hide resolved
Do you have a suggestion? I feel like it shouldn't return nothing as the result like with invalid math. |
Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com>
src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Outdated
Show resolved
Hide resolved
You can do that by registering a default value for strings using |
Yes I know, I was asking what you think the default should be (if not what it is now). |
You can just make it an empty string |
Summary
+
, e.g."foo" + "bar" = "foobar"
.Does not allow the joining of strings and numbers or other non-coercible objects.
concat(...)
function that permits joining anything into a single string (including non-texts).Description
I'm not a fan of strings as they are in Skript: I dislike that there's no true literal, I dislike how cumbersome and inefficient
"%...%"
interpolation is (both to write and to actually evaluate).Aside from interpolation, our only other option for joining strings is the expression
(concat[enate]|join) %texts% [(with|using|by) [[the] delimiter] %text%]
which has a rather unpleasant pattern (it sounds more like an effect than an expression).This is designed for joining texts, but it can't coerce types properly, so you still end up needing to use interpolation (or store things in middle man variables) to actually join things that aren't strings (e.g.
"your lucky number is "
and66
).What This Doesn't Do
In 2.7 or 2.8 (I forget which) a deliberate change was made to make illegal expressions in maths completely fail (evaluate to
<none>
) rather than be permitted as0
.This doesn't change that. This doesn't permit you to add
"hello"
and81
: it will fail at parsing time and, even if you try and get around that with variables, it will still evaluate to<none>
as intended.String addition ONLY supports adding strings together, whether they're from expressions, variables or
"..."
.String Addition
This pull request adds string addition arithmetic:
"A" + "B" = "AB"
.Lots of languages allow you to concatenate (glue together) strings. Most languages use
+
, some like to do their own thing with.
or&
or some other joiner.Just because other languages do something isn't a sufficient reason to add it to Skript, though.
I like it as a feature:
"%...%"
(especially if you have multiple interpolations in one text!)"a" + "b" = "ab"
than whatever's going on with"a%""b""%"
.String
concat(...)
FunctionThis pull request adds a
concat(...)
variable arguments function.This is more advanced than the
concatenate|join
expression, since it properly supports non-text parameters even without coercion.Concat takes in multiple objects and returns the result of all of them stringified and glued together.
Concat allows the joining of strings and objects, which are run through
Classes.toString
.Concat ALWAYS returns a text, even if none of the inputs are text. It doesn't do maths evaluation, it purely joins things into a text.
Target Minecraft Versions: any
Requirements: none
Related Issues: none