Raised This Month: $ Target: $400
 0% 

Float array into integer array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 12-04-2007 , 11:52   Float array into integer array
Reply With Quote #1

If I want to pass array of floats into set_task handler, what should I do? Currently, I'm splitting every float into integer and decimal part and storing them in 2 cells ... but I don't have a good feeling about that.

Is there a sort of a raw binary function that could do this??

Cheers!
__________________

Last edited by alien; 12-04-2007 at 11:52. Reason: typo as always
alien is offline
Send a message via ICQ to alien
Old 12-04-2007, 12:18
ConnorMcLeod
This message has been deleted by ConnorMcLeod. Reason: arkshine sample is right
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-04-2007 , 12:34   Re: Float array into integer array
Reply With Quote #2

No need to use enum().

It should be enough, I think.

Code:
    function( id )     {         static Float:fParam[2];                 fParam[0] = 10.0253;         fParam[1] = 45.1447;                 set_task( 1.0, "TestTask", id, _:fParam, 2 );     }             public TestTask( fParam[] )     {         log_amx( "fValue1 = %f | fValue1 = %f", fParam[0], fParam[1] );     }
__________________

Last edited by Arkshine; 12-04-2007 at 12:59.
Arkshine is offline
Old 12-04-2007, 12:37
Arkshine
This message has been deleted by Arkshine. Reason: double-post.
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 12-04-2007 , 15:00   Re: Float array into integer array
Reply With Quote #3

A lot of thanks, Arkshine!
+karma
__________________
alien is offline
Send a message via ICQ to alien
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 12-04-2007 , 15:04   Re: Float array into integer array
Reply With Quote #4

But if i'd like to send mixed contents?
__________________
alien is offline
Send a message via ICQ to alien
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-04-2007 , 16:13   Re: Float array into integer array
Reply With Quote #5

I would do with an enum(), I think.

Code:
    enum t_TaskTest     {         Float:fValue1,         iValue2,         String     };             new g_Params[ t_TaskTest ];     function( id )     {         g_Params[ fValue1 ] = _:14.25;         g_Params[ iValue2 ] = 10;         g_Params[ String  ] = EncodeText( "Hello word!" );         set_task( 1.0, "TestTask", id, g_Params, t_TaskTest );     }         public TestTask( g_Params[] )     {         static sText[16];         DecodeText( g_Params[ String ], sText, charsmax( sText ) );                 log_amx( "fValue = %.2f | iValue = %i | String = %s", g_Params[ fValue1 ], g_Params[ iValue2 ], sText );     }     EncodeText( const text[] )     {         return engfunc( EngFunc_AllocString, text )     }     DecodeText( const text, string[], const length )     {         global_get( glb_pStringBase, text, string,  length )     }

And it returns :
Code:
[Untitled.amxx] fValue = 14.25 | iValue = 10 | String = Hello word!
It requires fakemeta if you planned to use with string.
__________________

Last edited by Arkshine; 12-04-2007 at 16:16.
Arkshine is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 12-04-2007 , 16:15   Re: Float array into integer array
Reply With Quote #6

No not really - just integers and floats.
Thanks again ... both of your comments were very useful.
__________________
alien is offline
Send a message via ICQ to alien
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 11:10.


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