How to make a Max on a Variable based off another Variables Value?

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:
How to make a Max on a Variable based off another Variables Value?

I have a stat system in my mod and I want there to be a max energy. I thought I could do, if Energy > Intelligence*2 then Energy is no greater than or equal to Intelligence*2. But I can't even configure the modules like that. Please help! Here is the link to my screenshot of the procedure, thank you for your brain power!!!

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

Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You would use the set number…
Wed, 10/09/2024 - 08:16

You would use the set number block (which is a block below all the get number blocks of which you have used) and make it set Energy to [Intelligence*2] (in the case that energy is higher than intelligence).

The reason why your current setup isn't working is because you're trying to use a value, not a block. The difference between a value and a block is that a block is something in a chain of code which actually does things (e.g. replacing a mc block, or summoning an entity), whereas a value is something that you can use to tell blocks more specific info about what they should do (e.g. telling a set number block what value to set a variable to, or an if block the conditions that need to be met in order to continue with the flow that they have specified).

Hope this helped!

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It doesn't allow me to put…
Wed, 10/09/2024 - 16:51

It doesn't allow me to put the floating piece of get number Energy < or = get number Int*2 inside of the Set number block, i should've specified that first, my bad! Thanks for the timely response. 

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
 What your asking for doesnt…
Wed, 10/09/2024 - 17:09

 What your asking for doesnt make sense. You cant set a number to be a limit.

If you want it so energy cant surpass intelligence^2:

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I dont know why I thought it…
Wed, 10/09/2024 - 17:10

I dont know why I thought it said ^2 when it said *2. But its the same thing.

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh you mean i don't have to…
Wed, 10/09/2024 - 17:22

Oh you mean i don't have to do < or = to INT because its redundant if i just make it Set Energy to INT*2?

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I removed the if statement…
Wed, 10/09/2024 - 17:31

I removed the if statement as well and did what you said and it's working! Thanks a bunch for your time! If you have the chance maybe check out my other post about how to make percentage based mana bar, Thanks Again BUNCHES!

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OH WAIT I don't even have a…
Wed, 10/09/2024 - 17:36

OH WAIT I don't even have a post about that rip i'll post one later

Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Now that I have done this,…
Wed, 10/09/2024 - 18:15

Now that I have done this, my energy drain item cannot drain the energy below INT*2, I do need a max but I need it to be able to fluctuate as well

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The procedure above should…
Wed, 10/09/2024 - 23:12

The procedure above should only force the energy value to be at 2*int if its above 2*int. If for some reason one of your other procedures is constantly feeding energy, e.g. making energy go above 2*int then thats the problem.

For any and all other procedures involving energy, you should add an IF clause to check whether energy is below 2*int. Or more easily just make another variable called max energy which is set to 2*int on tick update. Then you just check whether energy is below max energy to be able to add any energy. You might also want to check if energy is below 0 and then set it to 0 etc.