Local variables for namespaces



  • As I was just testing something with local variables inside inline functions it occurred to me that we don't have the equivalent for namespaces and have to rely on var or reg.

    var is no good because of the scope:

    namespace MyNamespace
    {
        var aVariable = 10;
    }
    
    Console.print(aVariable); // 10
    

    And reg isn't ideal because of the limit of 32 and the performance decrease as you use more of them.

    @Christoph-Hart Could we get local variables for namespaces?



  • @d-healey wiered - I'm using locals all over my namespaces:

    inline function writeExpansion(expansionName)
    {
    
        // NEW STYLE
        local mySaveData;
        local myDataName; 
        for (e in expSet)
        {
            if (e.EName == expansionName)
            {
               myDataName = e.EName.replace(" ", "");
               Engine.dumpAsJSON(e, "../" + myDataName + "_MetaData.json"); 
               Console.print("writing:" + "../" + myDataName + "_MetaData.json"); 
            }
        }
    }
    


  • That's inside an inline function



  • @d-healey That's strange because const var is scoped to the namespace, but not var...



  • @ustk const is a different beast, because they can't be changed the precompiler can just replace them with fixed values, and scope isn't an issue. I've stopped using const var now and always just use const instead, since Christoph said they are both the same.



  • @d-healey That is 4 characters saved, seeing how fast I type I should definitely switch to this advanced coding technique 😁



  • @d-healey said in Local variables for namespaces:

    That's inside an inline function

    true - got me there officer, I will come quietly...



  • Could we get local variables for namespaces?

    I would say that if you exceed 32 variables in a single namespace it might be better to break down the code into multiple modules for clarity anyway. Also I'd like to keep local variables inside inline functions to not confuse people more.



14
Online

1.1k
Users

3.8k
Topics

33.4k
Posts