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

Solved Argument type mismatch on FloatToString(), even though it should be correct.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadowysn
Senior Member
Join Date: Sep 2015
Location: Location:
Old 04-15-2019 , 05:17   Argument type mismatch on FloatToString(), even though it should be correct.
Reply With Quote #1

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.

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.

Last edited by Shadowysn; 04-24-2019 at 07:55.
Shadowysn is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-15-2019 , 05:43   Re: Argument type mismatch on FloatToString(), even though it should be correct.
Reply With Quote #2

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]);
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 04-15-2019 at 08:52.
nosoop is offline
Shadowysn
Senior Member
Join Date: Sep 2015
Location: Location:
Old 04-15-2019 , 09:19   Re: Argument type mismatch on FloatToString(), even though it should be correct.
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
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.
Shadowysn is offline
Reply


Thread Tools
Display Modes

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 09:44.


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