CraftTweaker

CraftTweaker

151M Downloads

Returning an array of strings doesn't work in custom functions

iridiumlynx opened this issue ยท 13 comments

commented

Issue Description:

Returning a string[] doesn't work in custom functions. For some unknown reason an array of strings is treated as a string by return operator, causing 'bad return type' in crafttweaker.

What happens:

string[] is recognised as string

What you expected to happen:

string[] is recognised as string[]

Script used (Please Pastebin or gist your script, posting an unpasted or ungist'd script will automatically close this issue):

https://pastebin.com/CM3ZMcWJ

crafttweaker.log file (Please Pastebin or gist your file, posting an unpasted or ungist'd file will automatically close this issue):

https://pastebin.com/sUrDB92n


Affected Versions (Do not use "latest"):

  • Minecraft: 1.12.2
  • Forge: 1.12.2-14.23.5.2768
  • Crafttweaker: 1.12-4.1.14
  • Using a server: no
commented

Line 22~25:

    if isNull(szString) | isNull(szDelim)
    {
        return "";
    }

You return an empty string, which is not a string[]

commented

Thanks.

commented

Apart from the fact that "abcabcabc".split("a") should work as well ^^

commented

"abcabcabc".split("a") doesn't work because there is no field "split"

commented
for i in "abcabcabc".split("a") {
	print(i);
}

Prints:

[INITIALIZATION][CLIENT][INFO] 
[INITIALIZATION][CLIENT][INFO] bc
[INITIALIZATION][CLIENT][INFO] bc
[INITIALIZATION][CLIENT][INFO] bc
commented

if I change

    if isNull(szString) | isNull(szDelim)
    {
        return "";
    }

to

	if isNull(szString) | isNull(szDelim)
	{
		return [] as string[];
	}

that doesn't work.

commented

Yes, because you access invalid array indices.
The array you initialize has a length of 0, so you cannot set any of it's indices the way you do it.

commented

Thanks.
This:

for i in "abcabcabc".split("a") {
	print(i);
}

works fine.
Sorry, I just didn't read the log correctly(for approximately two days, maybe I should sleep more and go for a walk).

commented

But split function is undocumented! Should I post this issue to a documentation repository?

commented

Is there a function to parse a string using regular expressions?
And when the documentation will be upgraded?

commented

I do not know what you mean by that.

commented

https://docs.oracle.com/javase/8/docs/api/java/lang/String.html

You can use all of the methods, apart from the ones returning, or requiring a parameter of type char

commented

The documentation page https://crafttweaker.readthedocs.io/en/latest/#Vanilla/Variable_Types/Basic_Variables_Functions/ doesn't mention methods with parameters, only parameterless methods.