[Plugin] SwitchCase

0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • Plug-in: SwitchCase

    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)

    Changes

    • 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.

    Installation

    • Extract the contents of the zip file into \Construct2\exporters\html5\plugins
    • Folder name: wastrel_switchcase

    Features

    • 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

    Usage

    • 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.

    Conditions

    • 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.

    Actions

    • 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.

    Expressions

    • None

    Examples

    • switchcase_example.capx: Demonstrates the switch structure, all five case conditions, the default condition, and the break action.
  • ...Leave the break off to process the remaining case conditions...

    switch (var)
    case 0:  // if var == 0
    case 1:  // or var == 1
    case 2:  // or var == 2
        .... do something
        break

    You could add "compare" condition like "system condition:Compare two value", to be used in expression's "OR" operation.

    if var1 > 3
    or var2 < 5
    or var3 == 7
        .... do something

    Uh, it is not the same with traditional "switch case". So it might be better to create another plugin. <img src="smileys/smiley9.gif" border="0" align="middle" /> Sorry.

  • I added two new case statements, based on rexrainbow's feedback.

    The Case Compare condition allows the use of a comparison operator (=, !=, <, <=, >, >=) in conjunction with a value. The Switch variable is compared to the value using the selected operator.

    The Case List condition allows the entry of a list of values, each of which is compared individually. If a match is made, then the statement comes back as true. This effectively emulates an OR condition.

    And yes, these various case statements make this a non-standard switch-case structure, but I am not clever enough to come up with a better structure name.

    The files in the OP have been updated.

    Thanks!

  • Error 404

  • sayhitoarvind, try it now

  • Error 403. Is it still working with current C2 version btw?

  • lahssoo, try it again. It works with the latest version of C2.

  • Thanks a lot, my code will be readable

  • Wastrel where can i find the switchcase_example.capx ?

    thanks!

  • does anyone have a working example of this they'd be willing to share?

    much appreciated!

    -Rik

  • This is an old post but I needed it this morning and I had to figure out how to make it work.

  • Rik Marshall, sorry for the long delay. I have modified the OP with updated links to the plug-in and the example.

  • Wastrel WOOHOO!!! -- man i love this community !! thanks for your time / efforts / etc ... much appreciated!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hello Wastrel

    Is there any chanse that You will transform this plugin (Plugin SwitchCase (wastrel_switchcase) by Wastrel) from C2 to C3 ?

    using this guide->

    https://www.scirra.com/doc/c3sdk/portin ... ugins.html

  • Does this plugin support the new Construct 3?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)