AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Argument type mismatch on FloatToString(), even though it should be correct. (https://forums.alliedmods.net/showthread.php?t=315613)

Shadowysn 04-15-2019 05:17

Argument type mismatch on FloatToString(), even though it should be correct.
 
PHP Code:

public Action Command_Origin(clientargs)
{
    
float origin[3];
    
char stringy[9];
    
    
GetClientAbsOrigin(clientorigin);
    
FloatToString(originstringysizeof(stringy)); // Troublesome line
    
ReplyToCommand(clientstringy);
    
    return 
Plugin_Handled;


I had one job and I somehow blew it up. :bacon:

I was creating a one-time plugin to get the origin of a location.
It keeps giving me the argument type mismatch error on the first argument (origin), even though I was seemingly using a float.

Sourcemod is really confusing as the api (plus alliedmods api site) and error system don't really inform me of much, so if 'origin' was something like a vector I wouldn't know.

nosoop 04-15-2019 05:43

Re: Argument type mismatch on FloatToString(), even though it should be correct.
 
origin is a float[3] array, not a float. A float[3] is another name for a mathematical vector.

If you're meaning to access the first index of the array, use origin[0]. If your intent is to dump all three floats, you'll have to use origin[0], origin[1], and origin[2]. ReplyToCommand takes a format specifier string, so you can use "%f %f %f" and pass in each float in the array at the end like so:

Code:

ReplyToCommand(client, "%f %f %f", origin[0], origin[1], origin[2]);

Shadowysn 04-15-2019 09:19

Re: Argument type mismatch on FloatToString(), even though it should be correct.
 
Quote:

Originally Posted by nosoop (Post 2647607)
origin is a float[3] array, not a float. A float[3] is another name for a mathematical vector.

If you're meaning to access the first index of the array, use origin[0]. If your intent is to dump all three floats, you'll have to use origin[0], origin[1], and origin[2]. ReplyToCommand takes a format specifier string, so you can use "%f %f %f" and pass in each float in the array at the end like so:

Code:

ReplyToCommand(client, "%f %f %f", origin[0], origin[1], origin[2]);

Huh, arrays. Never really understood them more than a limit for strings.

Thanks for that, man.


All times are GMT -4. The time now is 18:24.

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