AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Float array into integer array (https://forums.alliedmods.net/showthread.php?t=63954)

alien 12-04-2007 11:52

Float array into integer array
 
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!

Arkshine 12-04-2007 12:34

Re: Float array into integer array
 
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] );     }

alien 12-04-2007 15:00

Re: Float array into integer array
 
A lot of thanks, Arkshine!
+karma

alien 12-04-2007 15:04

Re: Float array into integer array
 
But if i'd like to send mixed contents? :)

Arkshine 12-04-2007 16:13

Re: Float array into integer array
 
I would do with an enum(), I think. :mrgreen:

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.

alien 12-04-2007 16:15

Re: Float array into integer array
 
No not really - just integers and floats.
Thanks again ... both of your comments were very useful.


All times are GMT -4. The time now is 11:10.

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