Referenced parameters?
#1

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
Reply
#2

Check this page out, should be helpfull to you.

Reply
#3

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.
Reply
#4

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ɔ
Reply
#5

(Ўʞ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!)
Reply
#6

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...

Reply
#7

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:
Reply
#8

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
Reply
#9

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.
Reply
#10

And I need to turn my head to read it.
Reply
#11

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..
Reply
#12

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
Reply
#13

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.
Reply
#14

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

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
Reply
#16

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?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)