How is combo parameters used with a switch statement? (solved)

0 favourites
  • 3 posts
From the Asset Store
Combo
$10 USD
Button Combinations like in fightings, supports both keyboard and gamepads
  • Hey,

    I notice many vanilla behaviors have an action with an incoming parameter where a switch statement is used. Since you can't see the editor side aspects, I can't figure out how to use a combo type parameter with a switch;

    In c2, the parameters were numbers. I tried changing the json file to return a number, but that fails. Idk, looking for an example if anyone has one.

    What I want is: DoSomeAction(Choice, num){switch(choice)}

    Where in the editor, Choice is a drop down of options I have defined.

  • Ace.json

    	{
     {
     "id": "action-id",
     "scriptName": "ActionId",
     "highlight": false,
     "isAsync": true,
     "params": [
     {
     "id": "choice",
     "type": "combo",
     "items": [
     "item0",
     "item1",
     "item2"
     ]
     },
     {
     "id": "num",
     "type": "number"
     }
     ]
    }
    

    language

    	"action-id": {
     "list-name": "Execute Action",
     "display-text": "this is the display text, (Choice: [b]{0}[/b], num: [b]{1}[/b])",
     "description": "this is the description",
     "params": {
     "choice": {
     "name": "Choice",
     "desc": "This is the parameters description",
     "items": {
     "item0": "item_one",
     "item1": "item_two",
     "item2": "item_three"
     }
     },
     "num": {
     "name": "Num",
     "desc": "This is the parameters description"
     }
     }
    } 
    

    Code

    	ActionId(choice, num)
    {
     switch (choice)
     {
     case 0:
     
     console.log('item_one:', num);
     alert('item_one:', num);
     break;
     case 1:
     
     console.log('item_two:', num);
     alert('item_two:', num);
     break;
    
     case 2:
     
     console.log('item_three:', num);
     alert('item_three:', num);
     break;
     
     default:
     console.log('Invalid choice');
     
     }
    }
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wait, I'm confused,

    I thought I got some error when I tried to treat a combo parameter with a switch.

    Thanks. I probably did something stupid that I can't figure out now, because the below works just fine.

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