Skript icon indicating copy to clipboard operation
Skript copied to clipboard

new repeat() default function

Open Fusezion opened this issue 2 years ago • 3 comments

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

Fusezion avatar Sep 12 '22 12:09 Fusezion

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.

TheLimeGlass avatar Sep 13 '22 22:09 TheLimeGlass

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.

Fusezion avatar Sep 13 '22 23:09 Fusezion

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

Fusezion avatar Sep 14 '22 00:09 Fusezion

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

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)

Pikachu920 avatar Sep 24 '22 02:09 Pikachu920

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

Fusezion avatar Sep 24 '22 02:09 Fusezion

Removed repeat function in favor of adding a repeat expression.

Fusezion avatar Oct 04 '22 15:10 Fusezion

Changes should of been made now, sorry for the delay on those

Fusezion avatar Oct 24 '22 22:10 Fusezion

Can we also get some tests added for this?

TheLimeGlass avatar Nov 16 '22 22:11 TheLimeGlass

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"?

Fusezion avatar Nov 16 '22 22:11 Fusezion

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.

TheLimeGlass avatar Nov 16 '22 22:11 TheLimeGlass

Test skript should be added now, if you see anything I could do to it let me know

Fusezion avatar Nov 16 '22 22:11 Fusezion

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)

TPGamesNL avatar Nov 17 '22 08:11 TPGamesNL

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)

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

Fusezion avatar Nov 18 '22 04:11 Fusezion

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)

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.

AyhamAl-Ali avatar Nov 18 '22 08:11 AyhamAl-Ali