Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Checks whether the passed string is valid code.


Syntax:[code, allowEmpty, returnType] call fn_vbs_validateCode
  • code: String - Code to validate.
  • allowEmpty: Boolean - If true, then an empty code string is considered valid. If false, then code cannot be empty.
  • returnType: String - typeName that should match the type returned by the defined code. If empty (""), then no check is done (optional, default: "" ).
Return Value:Number - Validation result. Can be
  • 0: Valid code, and (if checked) code returns the specified type.
  • 1: String is empty, without it being allowed.
  • 6: Invalid code.
  • 7: Code returns the wrong data type.


When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.


Code checks:
_valid = ["alive player"] call fn_vbs_validateCode; // return 0 (valid code)
_valid = ["player setPos"] call fn_vbs_validateCode; // return 6 (invalid code)
Return type checks:
_valid = ["1+1",true,"SCALAR"] call fn_vbs_validateCode; // returns 0 (type match): "1+1" returns type "SCALAR"
_valid = ["player",true,"SCALAR"] call fn_vbs_validateCode; // returns 7 (wrong type): "player" returns type "OBJECT"

Additional Information

See also: fn vbs validateNumber, fn vbs validateCoords, isValidVarName, Engine Scripts Dialog Validator
Problems:When testing for 'returnType' the entered code will actually be executed in-game, so be aware of any effects this might have. It is probably better to only use this option with commands that just return data (e.g. getPos), rather than with commands that change properties (e.g. setPos).