Allows the developer to execute actions based on a traditional switch-case structure.
I originally developed this while designing a text parser in C2. I found that using the switch-case structure helped me to keep my event blocks more organized.Download SwitchCase plug-in (Version:01; Release date: 17 November, 2011)
- Added the Case Compare and Case List conditions
- Case Compare allows the selection of a comparison operator to be used in conjunction with the value
- Case List allows the entry of multiple items in a list, each of which will be compared separately. This effectively simulates an OR condition.
- Extract the contents of the zip file into \Construct2\exporters\html5\plugins
- Folder name: wastrel_switchcase
- Create switch-case structure to process actions
- Create Case conditions using a single value, a range of values, a comparison operator with a value, or a list of values
- Included a string search Case condition, since I already had it written
- Create a SwitchCase -> Switch event using an existing variable, the value of which will be checked in the Case statements. The action for this event should be empty.
- Create a SwitchCase -> Case sub-event, under the Switch event. Enter a value to check against the Switch variable. This value can be a number, string, or any type of variable.
- Add any number of actions that should be processed for that case.
- Add a SwitchCase -> Break action at the end of the action block, to bypass the remaining case conditions in the switch. Leave the break off to process the remaining case conditions.
- Add a SwitchCase -> Default sub-event at the end of the case conditions, to process a default condition. The Default event is optional.
- The case statements do not technically need to be sub-events of the switch statement. They will be processed no matter where they are in the event sheet, since they are all part of the same object. Adding them as sub-events just helps to better organize the sheet.
- Switch: Starts the SwitchCase block, using a single variable against which the Case statement values will be checked.
- Case: Adds a Case statement, using a single value to check against the Switch variable. Value can be an int, string, or any type of variable.
- Case range: Adds a Case Range statement, using a range of values to check against the Switch variable. Values can be int, string, or any type of variable.
- Case contains: Adds a Case Contains statement, using a single string value. Statement is true if the string is contained in the Switch variable.
- NEW Case compare: Adds a Case Compare statement, which combines a comparison operator (=, !=, <, <=, >, >=) and a value. Statement is true if the Switch variable meets the comparison condition to the value.
- NEW Case list: Adds a Case List statement, which allows the entry of a list of values. Each value is compared in succession, and when a value is equal to the Switch variable, the statement returns true. This effectively simulates an OR condition.
- Default: Adds a Default statment. The actions in the default statement will be run if no other case condition is true in the switch structure. There should only be one Default statement, and it is optional.
- Break: Adds a break action, to be placed at the end of a block of actions. This will bypass the remaining case conditions in the Switch structure. The break can be left off to continue processing case conditions.
: Demonstrates the switch structure, all five case conditions, the default condition, and the break action.