Please view the code below to see what I mean.
Sometimes
"INVALID_HANDLE" is fine but sometimes you must use
"view_as<KeyValues>(INVALID_HANDLE)" and sometimes both are fine. This inconsistency is annoying, and while we're at it, the whole new syntax, view_as stuff and methodmaps have made scripts ugly and difficult to quickly view and understand what's happening.
Tested on SM version 1.8.0.5973. You can compile and toggle the comments to test yourself.
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#define KV_INVALID_HANDLE view_as<KeyValues>(INVALID_HANDLE) // WTF SERIOUSLY
KeyValues g_hMapFile;
public void OnPluginStart()
{
g_hMapFile = OpenConfig(false);
// if( g_hMapFile != KV_INVALID_HANDLE ) // No error or warning.
if( g_hMapFile != INVALID_HANDLE ) // No error or warning.
{
delete g_hMapFile;
// g_hMapFile = INVALID_HANDLE; // warning 213: tag mismatch
g_hMapFile = KV_INVALID_HANDLE; // No warning
}
}
// Single function to open and return Handle/KeyValues datatype to use in various functions for adding/deleting/editing a config.
KeyValues OpenConfig(bool create = true)
{
// Create config if it does not exist
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), "%s", "data/l4d2_jukebox_spawns.cfg");
if( !FileExists(sPath) )
{
if( create == false )
{
// return INVALID_HANDLE; // warning 213: tag mismatch
return KV_INVALID_HANDLE; // No warning
}
File hCfg = OpenFile(sPath, "w");
hCfg.WriteLine("");
delete hCfg;
}
// Open the jukebox config
KeyValues hFile = new KeyValues("jukeboxes");
if( !hFile.ImportFromFile(sPath) )
{
delete hFile;
// return INVALID_HANDLE; // warning 213: tag mismatch
return KV_INVALID_HANDLE; // No warning
}
return hFile;
}
__________________