#Are there more efficient if-else statements?

1 messages · Page 1 of 1 (latest)

steel kelp
#

Is there a way to make more efficient if/else statements than looping through every alternative until you find the one you're looking for?

This is my current method, but I want to add more buttons, and I don't want it to be laggy:

wintry grailBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

steel kelp
#
execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"static"}]
execute if score button_pressed temp matches 1 run function pa:menu/update with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"back"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/back with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"w1"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/w1 with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"w1e"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/w1e with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"w2"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/w2 with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"w2e"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/w2e with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"item1"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/item1 with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"item2"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/item2 with storage minecraft:guis

execute store success score button_pressed temp run clear @s *[minecraft:custom_data~{Button:"item3"}]
execute if score button_pressed temp matches 1 run function pa:menu/buttons/item3 with storage minecraft:guis

(there are more, but discord character limit)

#

Forgot to mention: I am on 1.20.6

left pecan
wraith crypt
#

You could just do execute if items a bunch of times, probably

midnight coyote
left pecan
wraith crypt
midnight coyote
#

functions ccan only return ints

lofty wren
lofty wren
left pecan
midnight coyote
lofty wren
#

True

steel kelp
#

Item will be in the cursor, or if shift clicked in the inventory

steel kelp
midnight coyote
wraith crypt
#

execute if items entity @s container.* *[minecraft:custom_data~{Button:"w2e"}] run function … a bunch of times or whatever is what I would do. But yeah it doesn’t cover the cursor

#

If you do want to cover the cursor you can do that easily

#

Or at least I think you can

midnight coyote
#

You can by copying the code for the container check and change it for the cursor (this doubles the cheks though)

lofty wren
#

If it's only the cursor slot, you can still use execute if items

wraith crypt
#

Yeah you can just do player.cursor instead of container.*

#

Both for the inventory as well as the container