Hi, i am trying to write a L4D2 log plugin by methodmap which may make it more object-oriented, its code looks like this, and i saved it as a single ".sp" file.
PHP Code:
methodmap Logger __nullable__
{
// because the methodmap must has a constructor and the constructor cannot do nothing like 'public Logger() {}', so i use a bool value as a data
public Logger(bool enable)
{
return view_as<Logger>(enable);
}
// print the log info to all clients' console via VFormat and PrintToConsoleAll
public void debug(const char[] message, any ...)
{
char buffer[512];
VFormat(buffer, sizeof(buffer), message, 2);
PrintToConsoleAll(buffer);
}
// print the log info to the given client's console
public void debugToClient(int client, const char[] message, any ...)
{
if (client < 1 || client >= MaxClients || !IsClientInGame(client) || IsFakeClient(client)) { return; }
char buffer[512];
VFormat(buffer, sizeof(buffer), message, 3);
PrintToConsole(client, buffer);
}
// other logging methods...
}
And i writed a simple testing plugin to test the Logger and check if it works properly. The code for testing plugin looks like this.
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
// including the file "logging.sp"
#include "logger.sp"
public void OnPluginStart()
{
int a = 10;
float b = 20.0;
bool c = false;
char[] d = "hello";
// because Logger is nullable so we should use "new" to create an object, and use the "debug" method
Logger log = new Logger(true);
log.debug("test debug 1: int:%d, float:%.2f, bool:%b, string:%s", a, b, c, d);
// using method "debugInMainFile" from the testing plugin file
debugInMainFile("test debug 2: int:%d, float:%.2f, bool:%b, string:%s", a, b, c, d);
}
// this method is the same as the "debug" method in the file "logger"
public void debugInMainFile(const char[] message, any ...)
{
char buffer[512];
VFormat(buffer, sizeof(buffer), message, 2);
PrintToConsoleAll(buffer);
}
I am attamping to print the value of variables to all clients' console, but the outputs of the two methods are different, the console output is as follows.
PHP Code:
test debug 1: int:1953719668, float:0.00, bool:1000001101000000000000000000000, string:
test debug 2: int:10, float:20.00, bool:0, string:hello
We could see the output using method "log.debug" is incorrect while the output using method "debugInMainFile" is correct. I am wondering why, any help would be greatly appreiated, thank you
Sorry for my poor English...