adapap / OWScript

Python-like scripting language which transpiles into Overwatch Workshop script rulesets.
MIT License
37 stars 2 forks source link

Allow optional/default value in function parameter. #5

Closed MatthewSH closed 5 years ago

MatthewSH commented 5 years ago

To create reusable functions, it would help to allow default values in parameters.

Example:

%CreateEffect(pos, type? = Ring, color? = White)
    Create Effect
        Visible_To: Everyone
        Type: type
        Color: color
        Position: pos
        Radius: 1.5
        Reevaluation: Visible To

Adding ? to the end of the parameter will define it as an optional parameter. I pulled a page from the TypeScript book for this one. I like that because now we can detect when optional parameters are there and if it's not set...set it to null. So we can loosely have more control.

This would also make it so where the code is more like, "look bro, we have 3 parameters but only 1 is really required. As long as you give us the required...we're good." So instead of essentially counting and determining if we should use default values, we know when parsing the function initially when to consider them optional.