CraftTweaker

CraftTweaker

151M Downloads

Array / Loops not working

Thyriel opened this issue · 15 comments

commented

Issue Description:

Arrays / Loops don't work and produce severe errors

What happens:

Array / Loop with items, strings or integers results in errors

What you expected to happen:

A tutorial code that does not produce errors

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

Item: https://pastebin.com/dwdyaxz7
Copy & Paste code from your Array/Loop example page.

String script: https://pastebin.com/7MmeWMi0

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

Item log: https://pastebin.com/PRiwhhr0
String log: https://pastebin.com/4t7ysEPT


Affected Versions (Do not use "latest"):

  • Minecraft: 1.12.2 / 1.12.1
  • Forge: 14.23.0.2512 / 14.23.0.2501 / 14.22.1.2485 /
  • Crafttweaker: 4.08
commented

Could I please gets array.zs in its full entirety

commented

That is the full script in pastebin. I already removed everything else and still get these errors...

commented

Updated the logfiles in case i may have uploaded logfiles from before stripping the script file to the bare minimum.
Also updated some more Forge versions i tested, all with the same error as result. (All tested without any other mods installed)

commented

So, any idea on this ?
Bug, old example code or some weird non reproduceable bug on my side ?

commented

Try importing the classes and casting the types of the arrays

commented

What classes exactly and what means "casting the types of arrays" ?
As i said, it's just the tutorial code from http://crafttweaker.readthedocs.io/en/latest/#AdvancedFunctions/Arrays_and_Loops/
and there's neither class imports nor anything else in the code there. Could you please give a working complete example script on how to define an array correctly and use it in a simple loop ?

commented
Import crafttweaker.item.IItemStack;

val itemArray = [<minecraft:coal>,<minecraft:wood>] as IItemStack[];

for item in itemArray{
print(item.name);
}

Dunno if it works, am currently about 300km away from my computer ^^

commented

Nope, doesn't work: Error parsing test.zs:1 -- ; expected
But it helped getting closer to the problem when i found a similar example code at
http://crafttweaker.readthedocs.io/en/latest/#Tips_Tricks/General/Loops_Readability/
That script there works. So it indeed seems that arrays need an import and an "as ..." definition after the array itself.
The question is now: What do i need to import for a string array ?

commented
commented

Found it... Your example code is just garbage...
It's NOT "val stringArray = ["Hello", "World"];" as written at http://crafttweaker.readthedocs.io/en/latest/#AdvancedFunctions/Arrays_and_Loops/

It's: "val stringArray = ["Hello", "World"] as string[];"
...

commented

Instead of bashing the docs, why not make a PR to fix them? https://github.com/jaredlll08/CraftTweaker-Documentation

commented

Also it appears the issue has been solved, so I'm closing this.

commented

Sorry but something i just had to bash after spending hours to solve a problem that i'm sure you could have solved within a second if you would have looked at the code ;)

edit: Whats a PR ?

commented

Pull Request, it is you helping out essentially

commented

Technically the code works, it did when I wrote the scripts so something must've changed internally that caused this issue...