How to make an on/off variable

Started by ImKaiizuki on

Topic category: Help with modding (Java Edition)

Last seen on 23:30, 9. Aug 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make an on/off variable

I am currently trying to make a mod that adds potion effects on the click of a button (G) that when pressed once gives the effect press it a second time it removes it

Last seen on 17:49, 13. Oct 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This one is pretty simple,…
Thu, 08/08/2024 - 03:25

This one is pretty simple, just check if the player has the active effect, if they don't, give them the effect, if they do, remove the effect

Last seen on 23:30, 9. Aug 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it is not that simple; the…
Thu, 08/08/2024 - 20:35

it is not that simple; the problem i face is this when I press (G) it checks if i have a custom potion effect if i do it gives the effects of strength if i don't it does nothing. but when i do the procedure 

If event/entity has "custom potion effect"

      add potion effect "strength" 20 100000 to event/entity

             If event/entity has "strength"

                     clear all potion effects

                      add potion effect "custom potion effect" 255 1000000 to event/entity

 

when i press the button it all happens at the same time is there a way to toggle it on or off or maybe even skip it once

Last seen on 14:23, 13. Oct 2024
Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You did it wrong. Here is…
Thu, 08/08/2024 - 21:13

You did it wrong. Here is Step by Step Instructions for Keybindings Scenarios.

  1. Create a Global Boolean Variable with the Scope "Player Lifetime"

First in the "On Key Pressed" Trigger of you Keybind do the Following:

  • if [boolean]
    • set [boolean] to false
  • else
    • set [boolean] to true

After that create a Procedure with "On player tick update" or "On loaded entity tick update" Global Trigger:

  • if Has [event/target entity] active potion "custom potion effect"
    • if [boolean]
      • Add potion "strength" with level "20" for "100000" ticks to [event/target entity]
    • else
      • Remove specific potion effect "strength" from [event/target entity]
      • Add potion "custom potion effect" with level 255 for "1000000" to [event/target entity]

Of course you can modify it for yourself.

Last seen on 23:30, 9. Aug 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
please i have checked how do…
Fri, 08/09/2024 - 08:27

please i have checked how do u do boolean?

 

Last seen on 23:30, 9. Aug 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
nvm thx i figured out how to…
Fri, 08/09/2024 - 09:52

nvm thx i figured out how to make custom variables thank you soo much it works

 

Last seen on 14:08, 2. Sep 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
im new to modding and i have…
Sat, 08/17/2024 - 23:25

im new to modding and i have the same question but i dont understand your instructions. could you please explain in more depth.