Armor Infinitely Increasing Variable

Started by s_crowe31 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Armor Infinitely Increasing Variable

I want to have my armor piece increase my global variable "Energy" by 35 when equipped, however because the procedure is checking for whether the armor is equipped or not every player tick, it is also increasing "Energy" by 35 every player tick. Is there a way around this? Images with code blocks would be helpful, I'm very amateur at this, but any help is much appreciated. Thank you bunches for your time and brainpower!!!

Link to my current code block

https://www.dropbox.com/scl/fi/p2nrllex1naz26b0ixu0k/Screenshot-2024-10…

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need a logic in there…
Wed, 10/09/2024 - 16:58

You need a logic in there. You also dont need the repeat 1 times block. Make a local variable called (on) or something, or make a logic variable or nbt whatever you want.

 

If armor slot [2] = [custom armour]

     If logic (on) = false

        set logic (on) = true

        set number (Energy) to ([get energy] + 35)

Else if logic (on) = true

          set logic (on) = false

          set number (Energy) to ([get energy] - 35)

 

That should only add 35 energy when first putting on the chestplate. Then if they take off the chestplate it will remove the added energy.

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Will you be my mentor GOD…
Wed, 10/09/2024 - 17:39

Will you be my mentor GOD BLESS YOU! I will try this. I already know it will work oh powerful sensei! Thank you for you enlightening teachings master!

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
God you're gorgeous
Wed, 10/09/2024 - 17:40

God you're gorgeous

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To be honest I dont know if…
Wed, 10/09/2024 - 23:24

To be honest I dont know if a local variable will work. Thats why I said use either local variable, nbt or player variable. Try making a player variable instead of a local one and see if it works then.

You could also do this on item side. Eg make the item do an inventory tick, that way you can use a custom data logic tag instead of needing variables. Like this on tick event:

It may just be a local variable issue.

Also shouldnt your strength stat variable be player persistent? Otherwise everyone has the same and its not linked to any player.