CraftTweaker

CraftTweaker

151M Downloads

Bad local variable type exceptions

Dabombber opened this issue · 6 comments

commented

Issue Description:

I'm tying to exclude one item from an oredict entry in a recipe ingredient. I think my code is OK, /ct syntax has no problems with it, but it causes exceptions.

I guess it's because of the oring with an unset variable, but it even happens with example 3 where records should be set before oring.

What happens:

Bad local variable type

What you expected to happen:

Recipe added.

Scripts used:

  1. Bad local variable type
  2. Works, except for the unwanted rock
  3. Bad local variable type
  4. Bad local variable type
  5. Horrible, horrible success

crafttweaker.log files:

1. crafttweaker.log
3. crafttweaker.log
4. crafttweaker.log


Affected Versions:

  • Minecraft: 1.12
  • Forge: 1.12.2-14.23.5.2847
  • Crafttweaker: 1.12-4.1.20
  • Using a server: No
commented

Well, you need to initialize the variable with something.
Else, how would you do the OR in line 7?

You could initialize it with something from the oredict that you know matches.
Or you could ditch the whole and do it like
<ore:record>.only(function(item){return !item.matches(<minecraft:record_13>);})

Though that would still show that one record in JEI 🤔

commented

Yea, it shouldn't be ored while uninitialised in example 3, but it still bugs out. And example 5 is pretty much initialising from a known match, but it's a lot of code for something which should be simple.

Hopefully I'm missing some obvious way of doing it, but I couldn't find a complement to |. Something like <ore:record> ^ <minecraft:record_13> would be nice.

commented

Try something like

var records as IIngredient = null;
for item in <ore:record> {
    if(!item.matches(<minecraft:record_13>) {
        records = isNull(records) ? item : (records | item);
    }
}
commented

Also, I recommend joining Jared'S Blamejared Discord Server since usually more people reply there (and faster)

commented

This seems to work:

test.zs

import crafttweaker.item.IItemStack;
import crafttweaker.item.IIngredient;

var records as IIngredient = null;
for item in <ore:record>.items {
    if(!item.matches(<minecraft:record_13>)) {
        records = isNull(records) ? item as IIngredient: (records | item);
    }
}
recipes.addShapeless("lies", <minecraft:cake>, [records]);

but if I try to put it into a function it packs a sad.

EDIT: Still had a 1.12-4.1.19 version in one of my testing profiles, no problems with functions in 1.12-4.1.20.

It seems the third example can be made to work by initialising records to null, and item didn't even need to be cast as IIngredient so that must be some ternary operator thing.

commented

Closing this then.
If there are any other issues regarding this, please reply here and I'll reopen it.