Trouble with Local Variables

Started by revmykl777 on

Topic category: Help with MCreator software

Last seen on 02:37, 18. Sep 2023
Joined Oct 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Trouble with Local Variables

Okay, sorry if this has been discussed elsewhere, if it was I missed it. I am currently working on a mod that incorporates many RPG elements into minecraft. I've gotten a lot to work but I am having one issue. I would like to add Encumbrance to the game. The best way I can figure to do this would be to set a Local Variable for the blocks/items name it Weight, and give it a value. Then on my Master Player Code that runs on Update Tick, the code would calculate the weight of each item in the inventory (which will be easier after the next update according to the change log), and then slow the player's speed based on how heavy their items are. 

My issue is I have been trying to find a way for my master procedure to read a local variable from the block/item that is in my inventory. Essentially "code A" reads local variable from "code B" and makes use of the data. I've tried many ways and can't figure how to do this. Any help would be great, thanks!

Last seen on 14:30, 2. Aug 2022
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Local variables are only…
Sat, 10/10/2020 - 20:18

Local variables are only accessible inside their own procedures; you simply can't access them from another procedure. Instead, you probably want to use NBT data. NBT data is saved by the item and can be accessed from any procedure. To give and item an NBT tag with a number that is its weight you'll want to use the Set NBT number tag "tag name" of (Provided itemstack) to _ block found in the Item procedures tab. Just make "tag name" "weight", (Provided itemstack) to the itemstack you want to change the weight of, and _ to the weight of the item. To access the weight of the item use the Get NBT number tag "tag name" of (Provided itemstack) block.

Last seen on 02:37, 18. Sep 2023
Joined Oct 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much! Will try…
Sun, 10/11/2020 - 00:30

Thank you so much! Will try this when i get home!