View Single Post
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 07-31-2016 , 13:35   Re: [INC] Data String Parameter
Reply With Quote #4

Quote:
Originally Posted by KyleS View Post
Your example looks broken

Why would anyone ever need this? You'd simply pass const char sBuffer into the function call. If you need multiple, pass the amount and use [][]. This seems a little insane

PHP Code:
//Somewhere in the vast emptiness of a plugins source code
char sBuffer[12];
strcopy(sBuffersizeof(sBuffer), "Carrot");
FunctionCall(sBuffer)

void FunctionCall(const char sBuffer[])
{
    
//Do stuff

Code:
public void OnPluginStart()
{
	char sBuffer[12];
	strcopy(sBuffer, sizeof(sBuffer), "Test");
	SQL_TConnect(OnSQLConnect, "default", sBuffer);
}

public void OnSQLConnect(Handle owner, Handle hndl, const char[] error, const char[] sBuffer)
{
	PrintToServer(sBuffer);
}
Example using SQL_TConnect since it has the 'any data' or 'any ...' parameters to pass through cells. That doesn't work because the prototype is different so it outputs an error.

This works:
Code:
#include <sourcemod>
#include <data_string_parameter>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
	name        = "",
	author      = "",
	description = "",
	version     = "0.0.0",
	url         = ""
};

public void OnPluginStart()
{
	char sBuffer[12];
	strcopy(sBuffer, sizeof(sBuffer), "Test");
	SQL_TConnect(OnSQLConnect, "default", AnyString(sBuffer));
}

public void OnSQLConnect(Handle owner, Handle hndl, const char[] error, any data)
{
	char sBuffer[12];
	ReadAnyString(data, sBuffer, sizeof(sBuffer));
	
	PrintToServer(sBuffer);
}
Quote:
Originally Posted by Fyren View Post
Because you can't pass an array into a non-array parameter.
Sadly.

Last edited by Drixevel; 07-31-2016 at 13:41.
Drixevel is offline