View Single Post
API
Veteran Member
Join Date: May 2006
Old 10-12-2016 , 15:25   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #4

BUILT-IN SOLUTION BUT LEAST PERFORMANT
I see, you want to call the callback manually. Instead just invoke the command with FakeClientCommand:
Code:
void test(client)
{
    FakeClientCommand("sm_test %d", client);
    // instead of:    Command_Test(client, 1);
}
So yeah, to answer your question, you are best off just using FakeClientCommand()... AFAIK there is no abstraction on this process. You could also do this instead:

PERFORMANT AND TESTABLE SOLUTION BUT SLIGHTLY MORE CODE
Code:
RegConsoleCmd("sm_test", Command_Test);
public Action Command_Test(int client, int args)
{
    char arg[128];
    GetCmdArg(1, arg, sizeof(arg));
    
    int value = StringToInt(arg);
    return Command_Test_Internal(client, value);
}

public Action Command_Test_Internal(int client, int firstArg)
{
   // do your thing
}
void test(client)
{
    int someValue = 1234;
    Command_Test_Internal(client, someValue);
}
I tend to do this a lot since I like being able to unit test my code.

TAG MISMATCH ISSUE
As for your question about the tag mismatch... here you go:
Code:
if ( view_as<Colors>(g_iSelectedColor[client]) >= MAX_COLORS )
you could also go this too:
Code:
if ( g_iSelectedColor[client] >= view_as<int>(MAX_COLORS) )
Casting with view_as is easy
__________________

Last edited by API; 10-12-2016 at 15:37.
API is offline
Send a message via AIM to API