Trouble with Local Variables

Started by revmykl777 on Fri, 10/09/2020 - 20:06

Topic category: Help with MCreator software

Last seen on 02:02, 24. Nov 2020
Joined Oct 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Trouble with Local Variables
Fri, 10/09/2020 - 20:06

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 11:10, 23. Nov 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:02, 24. Nov 2020
Joined Oct 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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!