How to make an on/off variable

Started by ImKaiizuki on

Topic category: Help with Minecraft modding (Java Edition)

Active 1 year ago
Joined Aug 2024
Points:
66

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
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

Active 4 months ago
Joined Aug 2024
Points:
74

User statistics:

  • Modifications: 1
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 6
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

Active 1 year ago
Joined Aug 2024
Points:
66

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
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

Active 6 days ago
Joined Feb 2018
Points:
2015

User statistics:

  • Modifications: 1
  • Forum topics: 166
  • Wiki pages: 0
  • MCreator plugins: 3
  • Comments: 795
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.

Active 1 year ago
Joined Aug 2024
Points:
66

User statistics:

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

please i have checked how do u do boolean?

 

Active 1 year ago
Joined Aug 2024
Points:
66

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
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

 

Active 11 months ago
Joined Aug 2024
Points:
58

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1
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.