SA-MP Forums Archive
Referenced parameters? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: Referenced parameters? (/showthread.php?tid=62201)



Referenced parameters? - yom - 18.01.2009

Hi, i want to do a function like this

pawn Код:
native func(&p1, &p2); //func is a function of my plugin.

new a, b;
func(a, b);
printf("a=%d, b=%d", a, b);
How can i pass referenced parameters in my plugin? It may be basic, but yeah i'm a plugin noob



Re: Referenced parameters? - Donny_k - 18.01.2009

Check this page out, should be helpfull to you.




Re: Referenced parameters? - yom - 18.01.2009

Not really sorry,

an example of what i want to do:
pawn Код:
static cell AMX_NATIVE_CALL n_func(AMX *amx, cell *params)
{
  params[1] = 7;
  params[2] = 12;
  return 1;
}
So in Pawn i just do like in the first post, to get the message "a=7, b=12".

I have no idea of what to do to get it working.


Re: Referenced parameters? - yom - 19.01.2009

Ok got it working, by reading the implementor's guide a bit, and searching infos about amx_GetAddr

Here's how to do, still with my example function. Maybe it will help someone else:

pawn Код:
static cell AMX_NATIVE_CALL n_func(AMX *amx, cell *params)
{
  cell *cptr;

  if (!amx_GetAddr(amx, params[1], &cptr))
    *cptr = 7;

  if (!amx_GetAddr(amx, params[2], &cptr))
    *cptr = 12;

  return 1;
}
Ўssǝl‾ʎ 'ƃuıɥʇǝɯos pǝssıɯ ı ɟı ǝɯ ʇɔǝɹɹoɔ


Re: Referenced parameters? - rafay - 19.01.2009

(Ўʞo s,ʇı uǝɥʇ 'uʍop ǝpısdn puɐʇs uɐɔ noʎ ɟı) pɐǝɹ oʇ ǝ1qıssodɯı ʎ1ɹɐǝu & sʞɔns ʇı Ўsıɥʇ ǝʞı1 ǝdʎʇ ʇ,uop ǝsɐǝ1d

English:
Please don't type like this! It sucks & nearly impossible to read (If you can stand upside down, then it's ok!)



Re: Referenced parameters? - kc - 19.01.2009

Quote:
Originally Posted by Rafay
(Ўʞo s,ʇı uǝɥʇ 'uʍop ǝpısdn puɐʇs uɐɔ noʎ ɟı) pɐǝɹ oʇ ǝ1qıssodɯı ʎ1ɹɐǝu & sʞɔns ʇı Ўsıɥʇ ǝʞı1 ǝdʎʇ ʇ,uop ǝsɐǝ1d

English:
Please don't type like this! It sucks & nearly impossible to read (If you can stand upside down, then it's ok!)
What Orb wrote upside down was clearly a joke...




Re: Referenced parameters? - rafay - 19.01.2009

Quote:
Originally Posted by kc
Quote:
Originally Posted by Rafay
(Ўʞo s,ʇı uǝɥʇ 'uʍop ǝpısdn puɐʇs uɐɔ noʎ ɟı) pɐǝɹ oʇ ǝ1qıssodɯı ʎ1ɹɐǝu & sʞɔns ʇı Ўsıɥʇ ǝʞı1 ǝdʎʇ ʇ,uop ǝsɐǝ1d

English:
Please don't type like this! It sucks & nearly impossible to read (If you can stand upside down, then it's ok!)
What Orb wrote upside down was clearly a joke...

but i can't still read what he wrote. D:


Re: Referenced parameters? - yom - 19.01.2009

Strange, i think that for most people it's easy to read upside down, as it's easy to read with missing/mixed characters in words, and reconstitute the correct words. I'm not saying you aren't normal! And yes that was a joke about ******'s name being upside down, of course


Re: Referenced parameters? - kc - 19.01.2009

Quote:
Originally Posted by 0rb
Strange, i think that for most people it's easy to read upside down, as it's easy to read with missing/mixed characters in words, and reconstitute the correct words. I'm not saying you aren't normal! And yes that was a joke about ******'s name being upside down, of course
Yeah, it takes me a bit longer but I still have no problems with reading upside down.


Re: Referenced parameters? - Antironix - 19.01.2009

And I need to turn my head to read it.


Re: Referenced parameters? - yom - 15.05.2009

Ok, back to this problem, but this time with Floats!

My Pawn native:
pawn Код:
native func(&Float:p1, &Float:p2);

//..
new Float:a, Float:b;
func(a, b);
printf("a=%f, b=%f", a, b);

But.. what in the plugin? For example, this DOESN'T work:
pawn Код:
static cell AMX_NATIVE_CALL n_func(AMX *amx, cell *params)
{
  cell *cptr;

  if (!amx_GetAddr(amx, params[1], &cptr))
    *cptr = 7.564;

  if (!amx_GetAddr(amx, params[2], &cptr))
    *cptr = 12.789;

  return 1;
}
I obviously want that the Pawn part, print "a=7.564, b=12.789"

I'm clueless, hoping someone know..


Re: Referenced parameters? - ICECOLDKILLAK8 - 15.05.2009

Use this (sorry if it looks a mess but im writing from my phone) *cptr = amx_ftoc(7.564), That converts a float in to a cell


Re: Referenced parameters? - yom - 15.05.2009

Thanks a lot, it helped but i still have some problems so it's not fully working. I'll repost if i don't find solution.


Re: Referenced parameters? - ICECOLDKILLAK8 - 16.05.2009

Also the native dosent have to be an &Float, Just use Float


Re: Referenced parameters? - yom - 16.05.2009

What do you mean? They are referenced params, if you remove the & that's like if you pass a value that is 0, and the plugin can't send it's return value to it. I've just tested, when & removed, it also crash the server


Re: Referenced parameters? - yom - 22.11.2009

Bump, because i don't want to create another topic as my question is related to referenced parameters.

I need to know, is it safe to do this:
Код:
static cell AMX_NATIVE_CALL n_func(AMX *amx, cell *params)
{
  cell *cptr;

  amx_GetAddr(amx, params[1], &cptr))
  *cptr = 7;
  *(cptr-1) = 12; //this, instead of another amx_GetAddr call for getting physical address of params[2].

  return 1;
}
What do you think? Assuming the function is used correctly in Pawn, will it be safe?