[SOLVED!] Strings as reference parameters...
#1

Hi,

I'm trying to use a string as a reference parameter in a plugin I'm creating.

So far I have this:

Code:
//native Test(string[], size);
static cell AMX_NATIVE_CALL n_Test( AMX* amx, cell* params )
{
	char * string;
	sprintf(string,"test: %d", 1234);
	cell *buf;
	amx_GetAddr(amx, params[1], &buf);
	amx_SetString(buf, string, 0, 0, params[2]);
	return 1;
}
I'm pretty sure It's wrong, because when I try to do this in a gamemode:

pawn Code:
new teststring[16];
Test(teststring,sizeof(teststring));
SendClientMessage(playerid,0xFF000000, teststring);
That code causes the server to crash.

If anyone knows how to get this working, or can tell me what I'm doing wrong, I'd be appreciative of any help.

Thanks in advance,
CodeMatrix

EDIT: It does crash the server.
Reply
#2

It's a plugin problem. The plugin is what's not working.

I can write referenced parameters in C++ easily, but I don't know how to using amx_blah stuff.

What's the point of having a Plugin Development forum if your not allowed to ask questions relating to plugin development? Besides, if I did go to a C++ forum, they'd tell me to go to the forum of the Game I'm trying to make the plugin for, which is here.

I don't mean to be a dick or anything ssǝן‾ʎ, but I'm tired of people being told to go elsewhere, when all they want is to be helped.

Regarding help/tutorials, I have looked at the tutorial here:
http://forum.sa-mp.com/index.php?topic=103726.0

As you can see, the code I provided in my initial post resembles his example. Yet still it does not work for me.

I've also looked at an Old post by a guy named Orb, but it was using integers, which I can easily get using return. I also private messaged him to see if he actually managed to get referenced parameters working with strings as I'm trying to do. But I still haven't received a reply.

I only post if it's my last resort. I have looked at Pawn_Imp, etc. But I learn better by example rather than documentation.

Anyway, If anyone has a solution, PLEASE let me know.

Thanks again,
CodeMatrix
Reply
#3

My bad, lmao... It's always the simplest things.

Here's the working code for those who may need it:

Code:
// native Test(string[],size);
static cell AMX_NATIVE_CALL n_Test( AMX* amx, cell* params )
{
	char * string = new char[params[2]];
	sprintf(string,"test: %d", 1234);
	cell *buf = NULL;
	amx_GetAddr(amx, params[1], &buf);
	amx_SetString(buf, string, 0, 0, params[2]);
	delete [] string;
	return 1;
}
Thanks a billion ssǝן‾ʎ!

CodeMatrix
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)