SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 28/08/2009, 07:57 AM   #1
joco96
Big Clucker
 
Join Date: Nov 2007
Posts: 54
Reputation: 0
Default Callback problems

Hi!
I know there is another callback topic, but I have another problem. :/
I'm using this kind of callback:
Code:
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!
joco96 is offline   Reply With Quote
Old 28/08/2009, 11:50 AM   #2
Marcus09
Little Clucker
 
Join Date: Aug 2009
Posts: 7
Reputation: 0
Default Re: Callback problems

1) No.
2) Your executing the callback if it cannot find the callback. Remove the !.
Marcus09 is offline   Reply With Quote
Old 29/08/2009, 03:33 PM   #4
joco96
Big Clucker
 
Join Date: Nov 2007
Posts: 54
Reputation: 0
Default Re: Callback problems

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:
Code:
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 Code:
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...
joco96 is offline   Reply With Quote
Old 29/08/2009, 06:51 PM   #5
Incognito
Huge Clucker
 
Join Date: May 2006
Posts: 447
Reputation: 507
Default Re: Callback problems

You are not initializing the character array you are passing to amx_PushString or the integer you are passing to amx_Push:

Code:
char
	SomeString[256] = "string";
int
	SomeInt = 0;
Also, amx_FindPublic does return 0 on success, so that part of your code is correct.
Incognito is offline   Reply With Quote
Old 30/08/2009, 09:58 AM   #6
joco96
Big Clucker
 
Join Date: Nov 2007
Posts: 54
Reputation: 0
Default Re: Callback problems

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
joco96 is offline   Reply With Quote
Old 30/08/2009, 05:04 PM   #7
XPlatform
Big Clucker
 
Join Date: May 2008
Posts: 116
Reputation: 0
Default Re: Callback problems

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.
XPlatform is offline   Reply With Quote
Old 30/08/2009, 08:40 PM   #8
joco96
Big Clucker
 
Join Date: Nov 2007
Posts: 54
Reputation: 0
Default Re: Callback problems

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 =)
}
joco96 is offline   Reply With Quote
Old 10/11/2009, 11:33 AM   #9
Tony_Montana
Little Clucker
 
Join Date: Sep 2008
Posts: 25
Reputation: 6
Default Re: Callback problems

me too
i got a little probleme
i tried this in my plugin
Code:
	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 Code:
}

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
Tony_Montana is offline   Reply With Quote
Old 20/02/2010, 10:16 PM   #10
toby`
Little Clucker
 
Join Date: Feb 2010
Posts: 7
Reputation: 0
Default Re: Callback problems

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 ?
toby` is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there any callback for ..... MrIncredible Help Archive 4 15/03/2010 06:52 AM
Callback Bomber Help Archive 4 04/03/2010 09:08 PM
Is there such callback as JoeDaDude Help Archive 12 21/01/2010 06:29 PM


All times are GMT. The time now is 11:57 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.