Key Binding code Procedure

Started by Arenero_ on

Topic category: Help with Minecraft modding (Java Edition)

Active 9 hours ago
Joined Jan 2024
Points:
197

User statistics:

  • Modifications: 3
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 9
Key Binding code Procedure

I want to do a code with the key bindings for my mod (Minecraft Java 1.20.1, MCreator 2023.4)
The key binding code tat I want to use is *Home Down Down Down Down Down Right Home* to make spawn a entity
I can´t found much information and the bit that I could find it not works for me and I don't know why

Any help?
 

Active 5 days ago
Joined May 2022
Points:
1269

User statistics:

  • Modifications: 15
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1142
Key bindings, by default,…
Thu, 02/08/2024 - 15:09

Key bindings, by default, are only capable of tracking when a key is pressed and when that same key is released. If you wanted to do a string of keys, you would need some player-lifetime number variables to keep track of how many keys have already been pushed.

Active 9 hours ago
Joined Jan 2024
Points:
197

User statistics:

  • Modifications: 3
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 9
Can you do a short tutorial…
Fri, 02/09/2024 - 17:46

Can you do a short tutorial or something?
I dont use much the variables and the tutorials are not very helpful

Active 5 days ago
Joined May 2022
Points:
1269

User statistics:

  • Modifications: 15
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1142
You need to go to the …
Fri, 02/09/2024 - 23:46

You need to go to the 'variables' menu in the main workspace. On the left hand side of the workspace there should be a tab that says 'variables.' 

Once there, you want to create a new number variable, and name it whatever you want. (I'll call it 'keys pressed.') 

Then, whenever one of your keybinds is pressed, check what number the variable is currently on to know which is the next key that needs to be pushed. (0 means 'home' needs to be pushed, 1 means 'down' needs to be pushed, etc.) If the key that was pressed is correct, increase the variable by one. Otherwise, reset it to zero. When the number reaches its maximum value, you'll know the full key sequence has been entered, and you can run the procedure.