Raised This Month: $51 Target: $400
 12% 

Dynamic number of arguments in functions


Post New Thread Reply   
 
Thread Tools Display Modes
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 07-27-2010 , 14:49   Re: Dynamic number of arguments in functions
Reply With Quote #11

The any tag that you are using is to prevent tag mismatch warnings when using the function.

Casting the getarg native with bool/float/etc. just changes the association of the variable to prevent tag mismatch warnings within the function.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Old 09-30-2010, 10:31
alexx109
This message has been deleted by Exolent[jNr]. Reason: Double post.
alexx109
Junior Member
Join Date: Jun 2010
Location: Brazil
Old 09-30-2010 , 10:42   Re: Dynamic number of arguments in functions
Reply With Quote #12

And what about by-reference vars? Arrays are still passed by-ref even as a dynamic argument catched by get_arg?

And about int vars as ref, in "normal" function headers we use & to flag them as passed-by-ref...

I guess it is through set_string, set_array and set_param_byref, am I correct?
alexx109 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-30-2010 , 13:40   Re: Dynamic number of arguments in functions
Reply With Quote #13

Quote:
Originally Posted by alexx109 View Post
And what about by-reference vars? Arrays are still passed by-ref even as a dynamic argument catched by get_arg?

And about int vars as ref, in "normal" function headers we use & to flag them as passed-by-ref...

I guess it is through set_string, set_array and set_param_byref, am I correct?
No, those functions are used in dynamic natives.

Here is an example for an array in dynamic arguments:
Code:
foo( ) {     new iArray[ 32 ];     // pretend the array has values         EmptyArray( iArray, sizeof( iArray ) ); } bar( ) {     new iValue = 3;     GetValue( iValue );     // iValue = 5 now } // EmptyArray( array[], const size ) EmptyArray( ... ) {     new size = getarg( 1 );         for( new i = 0; i < size; i++ )     {         setarg( 0, i, 0 );         // setarg( arg, array_index, value )         // same as doing:         array[ i ] = 0;     } } // GetValue( &value ) GetValue( ... ) {     setarg( 0, _, 5 ); }

I'm not sure about the byref integer, but the array should work.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 09-30-2010 at 13:44.
Exolent[jNr] is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 09-30-2010 , 13:53   Re: Dynamic number of arguments in functions
Reply With Quote #14

What deos byref really means ??
I cant understand it
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-30-2010 , 13:54   Re: Dynamic number of arguments in functions
Reply With Quote #15

Quote:
Originally Posted by abdul-rehman View Post
What deos byref really means ??
I cant understand it
by-reference
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-30-2010 , 17:48   Re: Dynamic number of arguments in functions
Reply With Quote #16

Quote:
Originally Posted by Exolent[jNr] View Post
by-reference
Which translates into pointer reference.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 10-01-2010 , 13:20   Re: Dynamic number of arguments in functions
Reply With Quote #17

Quote:
Originally Posted by ot_207 View Post
Which translates into pointer reference.
Quote:
Originally Posted by Exolent[jNr] View Post
by-reference
I know that it means by reference/ pointer reference but what deos it do in reality
for eg i saw a post in which the coder was trying to do this:
PHP Code:
new Floatvalue pev(idpev_fuser2
And in the next post arkshine said that it was wrong and he said that the float values need to be passes as by-reference values like this:
PHP Code:
new Float:somthing
pev
idpev_fuser2somthing
What is the difference ??
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-01-2010 , 13:34   Re: Dynamic number of arguments in functions
Reply With Quote #18

If the value is 3.5, the first will return 3 and second 3.5.
__________________
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2010 , 21:22   Re: Dynamic number of arguments in functions
Reply With Quote #19

@abdul_rehman

pev() funcwiki
Code:
To retrieve an integer, supply no extra parameters.
To retrieve a float, pass a single float by reference.
To retrieve a string, pass a string array and max length.
The pev function itself returns an integer.
PHP Code:
new IntVar pevid pev_whatever ); 
Passing 1 additional param will pass a float byref.
PHP Code:
new Float:FloatVar;
pevid pev_whatever FloatVal ); 
Passing 2 additional params will pass a string byref for max length.
PHP Code:
new StringVar10 ];
pevid pev_whatever StringVar charsmaxStringVar ) ); 
__________________
Bugsy is offline
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 10-03-2010 , 05:22   Re: Dynamic number of arguments in functions
Reply With Quote #20

PHP Code:
new Floatvalue pev(idpev_fuser2
This gave me 0, pev_fuser2 being 2.1.
__________________
ehha is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 06:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode