- Notifications
You must be signed in to change notification settings - Fork 0
Tutorial: Switch
Note: This was pulled from the tutorial. It may need to be cleaned up and placed elsewhere.
####Switch Routines
Switch routines complement Conditional statements with a different method of control commonly referred to as "branching". Switches are designed to work very similarly to switch statements in Java, and have relatively simple syntax:
- 'switch.something':
- 'FirstCase':
[SOME STATEMENTS]
- 'SecondCase':
[SOME STATEMENTS]#...etc.#Sample Spawn configSpawn:
- 'switch.entity.type': # You must use "entity" in this EntityType conditional, # due to an update.
- 'Creeper': 'range(3,7)'# A simple equation that defines an upper and lower bound that randomly assigns# a value between that range. In this example, Creepers now spawn with # health between 3 and 7.
- 'Ghast': '0'# If a nonpositive result is calculated for spawning, it simply cancels the event :D
- 'Human': '15'# Give 'em something to aspire to.
- 'Player': '14'There is a problem that may not be immediately obvious with this configuration - the Player case never gets executed! As we mentioned before, Player is a subcategory of Human - and thus any Player would get caught by the Human case! Switches only execute a single case - this is what makes them unique in regard to Conditionals. Be wary of these potential logical mistakes as you configure MD. Also know that there is a switchall option, which can execute Multiple cases in the same set.