Hi guys,
I’m seeing confusing behaviour when trying to write classes that are intended for singleton use (and don’t feature a constructor).
For example:
`class TestClass
{
_myNumber = 0;
function setMyNumber()
{
server.log( _myNumber );
_myNumber = 1;
}
}
TestClass.setMyNumber();`
Result:
I can read/log the number but I can’t set it, resulting in: “cannot set property of object of type ‘class’”. I get exactly the same result if I set it to static.
If I attempt to instance my class:
`class TestClass
{
_myNumber = 0;
function setMyNumber()
{
server.log( _myNumber );
_myNumber = 1;
}
}
local testClass = TestClass();
testClass.setMyNumber();`
Result:
This solves the issue, however, if I make _myNumber static to share it across instances, it can’t be found as a property. In C++ I would use the namespace i.e. TestClass::_myNumber but I can’t find the equivalent here?
I think perhaps I need a quick Squirrel-lang Classes / Static 101, can anyone advise?
Many thanks