Skript
Skript copied to clipboard
new repeat() default function
Description
This PR aims to add a new repeat() function that utilizes java's built in repeat() method for strings.
While this is a minor change I do believe it's been something skript has been missing for awhile now.
Target Minecraft Versions: any Requirements: none Related Issues: none
Skript has it's own implementation of multiply in StringUtils https://github.com/SkriptLang/Skript/blob/6bf23414910250bfaa65933adbacd9311733b536/src/main/java/ch/njol/util/StringUtils.java#L291-L313
I haven't checked if it would be more efficient to use Skript's or not. The collection util in Java probably didn't exist back then. We need to ensure this is currently the most efficient operation count. The old method might even be better to replace with new, or vice versa.
Skript has it's own implementation of multiply in StringUtils
https://github.com/SkriptLang/Skript/blob/6bf23414910250bfaa65933adbacd9311733b536/src/main/java/ch/njol/util/StringUtils.java#L291-L313
I haven't checked if it would be more efficient to use Skript's or not. The collection util in Java probably didn't exist back then. We need to ensure this is currently the most efficient operation count. The old method might even be better to replace with new, or vice versa.
It's entirely possible that skript's method would be better with the fact it's built for string while nCopy seems to support
use of non string types and if I compare multiply with Java11 repeat the only difference is some limitations and checks most of everything else is the same. If you have any clue on how I could possibly test which one is more suited then I'd love to hear.
Moved it to multiply just to keep it with current standards of skript if we ever decide that multiply is outdated we can update it then
Moved it to
multiplyjust to keep it with current standards of skript if we ever decide thatmultiplyis outdated we can update it then
I think lime was just suggesting you use the function in your code. as a name, I think multiply is a lot less clear than repeat. Also, what do you think about making this an expression? I think "string" repeated 5 times is probably clearer than repeat("string", 5)
I think lime was just suggesting you use the function in your code. as a name, I think
multiplyis a lot less clear thanrepeat. Also, what do you think about making this an expression? I think"string" repeated 5 timesis probably clearer thanrepeat("string", 5)
I think I could do that tho would it be best to keep repeat function and add it as a side option like how round is
or just removing the function entirely and adding a %string% repeated %number% times
Removed repeat function in favor of adding a repeat expression.
Changes should of been made now, sorry for the delay on those
Can we also get some tests added for this?
Can we also get some tests added for this?
Yeah I could see about doing that what would be the best method for doing it?
assert if length of {_msg} < X with "Multiply failed to convert"?
Can we also get some tests added for this?
Yeah I could see about doing that what would be the best method for doing it?
assert if length of {_msg} < X with "Multiply failed to convert"?
Sure. You can also check the exact expected string outcome against it.
Test skript should be added now, if you see anything I could do to it let me know
Shouldn't "ABC" repeated 0 times return an empty string? Also, "ABC" repeated {_none} times should return null IMO, not "ABC", same with negative IMO.
You can add a warning if you want, but do it in init (check if it's a literal first)
Shouldn't
"ABC" repeated 0 timesreturn an empty string? Also,"ABC" repeated {_none} timesshould return null IMO, not"ABC", same with negative IMO.You can add a warning if you want, but do it in init (check if it's a literal first)
tbh I don't really see it being needed, with the fact the string input exist I believe we should atleast return the string I feel like if we don't return the string people will mistake it as something is wrong with our string, and not the number
Shouldn't
"ABC" repeated 0 timesreturn an empty string? Also,"ABC" repeated {_none} timesshould return null IMO, not"ABC", same with negative IMO.You can add a warning if you want, but do it in init (check if it's a literal first)
Repeated 0 times should return the same string IMO as we're talking about repeating which as how I understand it it should be original string + repeats and if repeats are 0 then we're left with original string, correct me if I am wrong.
In addition to that negative values shouldn't print a warning, just ignore it.