Callback problems -
joco96 - 28.08.2009
Hi!
I know there is another callback topic, but I have another problem. :/
I'm using this kind of callback:
Код:
cell
amx_addr,
amx_ret,
* amx_physAddr;
int
amx_idx;
if (!amx_FindPublic(pAMX, "SomeFunction", &amx_idx))
{
amx_PushString(pAMX, &amx_addr, &amx_physAddr, SomeString, 0, 0);
amx_Push(pAMX, SomeInt);
amx_Exec(pAMX, &amx_ret, amx_idx);
amx_Release(pAMX, amx_addr);
}
I call a function from Pawno like StartListening.
and then the function in the plugin saves the amx variable (pAMX = amx).
and then later if there is an incoming data it calls the callback with the same amx.
but I'm using this amx 2 times like 2 callbacks, can it be a problem?
And the callback doesn't works. I put a printf in the callback and it doesn't appears :/.
Please answer my questions, and give me a good callback example

.
Thanks!
Re: Callback problems -
Marcus09 - 28.08.2009
1) No.
2) Your executing the callback if it
cannot find the callback. Remove the !.
Re: Callback problems -
Correlli - 28.08.2009
http://forum.sa-mp.com/index.php?topic=94340.0
Re: Callback problems -
joco96 - 29.08.2009
Quote:
Originally Posted by Marcus09
1) No.
2) Your executing the callback if it cannot find the callback. Remove the !.
|
1) Ok
2) I know it calls it, but there is another problem...
When it calls the function the printf doesn't appear.
Like:
Plugin callback:
Код:
char
SomeString[256];
cell
amx_addr,
amx_ret,
* amx_physAddr;
int
amx_idx,
SomeInt;
if (!amx_FindPublic(pAMX, "OnSomethingHappens", &amx_idx))
{
amx_PushString(pAMX, &amx_addr, &amx_physAddr, SomeString, 0, 0);
amx_Push(pAMX, SomeInt);
amx_Exec(pAMX, &amx_ret, amx_idx);
amx_Release(pAMX, amx_addr);
}
Pawno callback:
pawn Код:
public OnSomethingHappens(someint, somestring[]) {
printf(somestring);
}
And then there are empty spaces in the server window.
Like:
"
Somebody joined the server.
<== Here is the printf. Nothing here
Somebody left the server.
"
And sometimes it getting crazy... It gets the last string, not the new :/.
So I don't know what's the problem...
Re: Callback problems -
Incognito - 29.08.2009
You are not initializing the character array you are passing to amx_PushString or the integer you are passing to amx_Push:
Код:
char
SomeString[256] = "string";
int
SomeInt = 0;
Also, amx_FindPublic does return 0 on success, so that part of your code is correct.
Re: Callback problems -
joco96 - 30.08.2009
Hi, again!
Now I can printf the variable(SomeString). But if I want to print it like this: printf("SomeString: %s", somestring);
I get this:
SomeString:
But If I print just the somestring var like this: printf(somestring);
I get the var's value :/.
So I don't know what's the problem...
Please help me
Re: Callback problems -
XPlatform - 30.08.2009
Quote:
Originally Posted by [HUN
Peti ]
Hi, again!
Now I can printf the variable(SomeString). But if I want to print it like this: printf("SomeString: %s", somestring);
I get this:
SomeString:
But If I print just the somestring var like this: printf(somestring);
I get the var's value :/.
So I don't know what's the problem...
Please help me
|
Usually if I use printf("Thestring: %s", var); and get "Thestring: " as output, it's because the "var" variable is empty.
Try using something like printf("TestString: %s", "Here it is!"); If that works, then your variable being passed is empty.
Re: Callback problems -
joco96 - 30.08.2009
Quote:
Originally Posted by CodeMatrix
Quote:
Originally Posted by [HUN
Peti ]
Hi, again!
Now I can printf the variable(SomeString). But if I want to print it like this: printf("SomeString: %s", somestring);
I get this:
SomeString:
But If I print just the somestring var like this: printf(somestring);
I get the var's value :/.
So I don't know what's the problem...
Please help me
|
Usually if I use printf("Thestring: %s", var); and get "Thestring: " as output, it's because the "var" variable is empty.
Try using something like printf("TestString: %s", "Here it is!"); If that works, then your variable being passed is empty.
|
I fixed the problem:
function OnSomethingHappens(somestring[]) {
new string[256]
format(string, sizeof(string), "%s", somestring);
printf("SomeString: %s", string); // It works =)
}
Re: Callback problems -
Tony_Montana - 10.11.2009
me too
i got a little probleme
i tried this in my plugin
Код:
int clients = 2;
if(amx_FindPublic(amx, "OnClientConnect", &clients) == AMX_ERR_NONE)
{
amx_Push(amx, clients);
amx_Exec(amx, &amx_ret, clients);
amx_Release(amx, amx_addr);
}
else
{
logprintf("there is a probleme");
}
return 1;
my function looks good
now this is my pawn code
pawn Код:
}
public OnRconCommand(cmd[])
{
if(strcmp(cmd, "test", true) == 0)
{
Test();
return 1;
}
return 1;
}
public OnClientConnect(clients)
{
printf("%d clients", clients);
if(clients == 1)
{
printf("the first client");
}
else if(clients == 2)
{
print("the second one");
}
}
ok my function is Test()
and it calls the callback "OnClientConnect(clients)"
so clients must be 2 as you see here "int clients = 2;"
but it always print "22 clients" for me even if i change "int clients = 3;"
what is the probleme here ?
thx
Re: Callback problems -
toby` - 20.02.2010
Quote:
Originally Posted by Y_Leѕѕ
You're using amx_FindPublic wrong - compare all the other examples to yours.
|
Hi, I am trying to accomplish the same task. (push my data to a callback) the only examples I have found use "amx_FindPublic", would you kindly point to an alternative ?