Need help understanding how to redefine variables. #169
Answered
by
Zergatul
BamaJoe411
asked this question in
Q&A
-
|
Im trying to expand the wheat automation example to other crops but it's not working. here is my script. in the third if block my string blockBroken = "";
if (game.blocks.getId(x, y, z) == "minecraft:wheat") {
if (game.blocks.getIntegerTag(x, y, z, "age") == 7) {
blockBroken = "wheat";
blockAutomation.breakBlock();
}
}
if (game.blocks.getId(x, y, z) == "minecraft:carrots") {
if (game.blocks.getIntegerTag(x, y, z, "age") == 7) {
blockBroken = "carrots";
blockAutomation.breakBlock();
}
}
if (game.blocks.canBeReplaced(x, y, z)) {
if (game.blocks.getId(x, y - 1, z) == "minecraft:farmland") {
if (blockBroken == "wheat") {
blockAutomation.useItem("wheat_seeds", "from-top");
} else if (blockBroken == "carrots") {
blockAutomation.useItem("carrot", "from-top");
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
Zergatul
Jul 24, 2025
Replies: 1 comment
-
|
This variable is local, for every script invocation it will be using another instance. static string blockBroken = "";It should be defined at the beginning of the script. It will get reset if you recompile script. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
BamaJoe411
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This variable is local, for every script invocation it will be using another instance.
You can declare "static" variable that will persist between multiple script invocations:
It should be defined at the beginning of the script. It will get reset if you recompile script.