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

Solved Can't check if an argument is a specific string, "argument type mismatch"?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZwipZwap Zapony
Junior Member
Join Date: Feb 2016
Old 11-07-2017 , 11:40   Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #1

I'm trying to code a SourceMod plugin for Team Fortress 2 that allows one to add/remove "conditions" on oneself, but the compiler doesn't like what I'm trying to do. (The compile log is gone now, but it used to have some errors I couldn't figure out, though it doesn't anymore.) And as for what I'm trying to do, refer to the attached SP script file. (Please forgive the coding if possible. I'm not a coding expert.)

Based on searching around a bit, it seems like the "argument type mismatch" error I'm getting is about using a type of variable while it expects a different type... but I really can't seem to make it expect what it gets for this? (Note that Function_ConditionNameToInt only receives string inputs where it gets used, and that that's what I'm trying to use it for.)

Edit 1: I'm using one of the latest "unstable" SourceMod builds, by the way.

Edit 3: The (now-working) SP script has been attached to this post, since that's an option. As for how I fixed the issues, refer to the comments below.
Attached Files
File Type: sp Get Plugin or Get Source (TF2-SetCond.sp - 251 views - 9.3 KB)

Last edited by ZwipZwap Zapony; 11-09-2017 at 11:03.
ZwipZwap Zapony is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 11-07-2017 , 14:54   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #2

You're missing parentheses around the if conditions
Miu is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-07-2017 , 15:17   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #3

Also you'd probably save yourself some hassle if you just made a .cfg file which contained a KeyValue, the key being the search term and the value being the condition Integer value. Then when the plugin loads save the keyvalue into a StringMap handle. That way you no longer have to hard code the values plus you can add in custom aliases.
Mitchell is offline
ZwipZwap Zapony
Junior Member
Join Date: Feb 2016
Old 11-07-2017 , 15:20   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #4

Quote:
Originally Posted by Miu View Post
You're missing parentheses around the if conditions
Adding parantheses around them, so line 33 looks like ~ if (StrEqual(input, "uber", false) || StrEqual(input, "ubercharge", false)) ~, changes nothing. I get the (exact) same errors for the same line numbers when trying to compile it that way. (If that's not how you meant for me to change it, please explain it more.)

Edit 2: Actually, nevermind, I don't get the exact same errors. I no longer get the ~ error 001: expected token: "*then", but found "return" ~ error. But I still get the ~ error 035: argument type mismatch (argument 1) ~ error.


Edit 1:
Quote:
Originally Posted by Mitchell View Post
Also you'd probably save yourself some hassle if you just made a .cfg file which contained a KeyValue, the key being the search term and the value being the condition Integer value. Then when the plugin loads save the keyvalue into a StringMap handle. That way you no longer have to hard code the values plus you can add in custom aliases.
Well, I don't know exactly how to do that (and don't want to dive into trying to figure it out until I get the plugin working in the first place), and to be honest, I tried to code it like that somewhat to avoid using such a configuration file (as weird as that may sound).

Last edited by ZwipZwap Zapony; 11-07-2017 at 15:31.
ZwipZwap Zapony is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-07-2017 , 17:12   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #5

I didn't attempt to compile your code, but just skimmed the beginning of the function with the errors you asked about.

The type mismatch is because the input parameter for your function is an integer and not char[].

The expected token error is because you didn't add parentheses around the conditions for all the if statements. (Technically, there's some ancient code in the compiler that would let you not use them, but that will likely get excised now that it's been brought up by your post.)

Edit: just made the compiler change, but probably won't show up in snapshots till 1.10. The error reported for something like if a == b { ... will be expected "(", found "-identifier-".

Last edited by Fyren; 11-07-2017 at 18:37.
Fyren is offline
ZwipZwap Zapony
Junior Member
Join Date: Feb 2016
Old 11-08-2017 , 07:45   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #6

Quote:
Originally Posted by Fyren View Post
- The type mismatch is because the input parameter for your function is an integer and not char[]. -
I knew that already, I just didn't know how to make it know it's supposed to be a string, and had already tried many things. One thing I hadn't tried, though, was changing it from int Function_...(input) to int Function_...(char[] input), though I had previously tried that without the [].

After doing that change (just to clarify, I mean using char[] with the []), I get no errors when trying to compile it anymore... but I still get warnings about tag mismatches for each return TFCond_...; line.

Are the TFCond_ constants (found in -/include/tf2.inc) not integers, and if not, what should I do to fix that? (I haven't tried seeing if the plugin works yet, as I'd like to get rid of any compile warnings first.)
ZwipZwap Zapony is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-08-2017 , 18:09   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #7

The tag for an enum is the name of the enum.
Fyren is offline
ZwipZwap Zapony
Junior Member
Join Date: Feb 2016
Old 11-09-2017 , 09:06   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
The tag for an enum is the name of the enum.
I see... So, if I understand you correctly, I should change the function from an int to a TFCond? Doing so, all of the tag mismatches disappeared, though are replaced with a few new ones in the lines where I return an integer in the function, and try to do math on the result of the function. That's better, though.
Then, after a little testing myself, it seems I can change if (condition < 0) to if (view_as<int>(condition) < 0) to fix the warnings with the math usage, and likewise for making the function view the few integer values as TFCond numbers.

Making those changes where needed, the compile log is now completely error- and warning-less (and as a plus, the plugin even works just like I hoped for). Thank you.
ZwipZwap Zapony is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-09-2017 , 10:40   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #9

Quote:
Originally Posted by ZwipZwap Zapony View Post
Edit 2: The SP script and compile log have been removed, now that it seems to work.
This is against our rules - you can attach the source code and log as files to your post rather than linking offsite if CloudFlare wont let you post them inline.

Please also use the Advanced Edit mode to mark your post as solved while you're in there uploading attachments.
__________________

Last edited by asherkin; 11-09-2017 at 10:40.
asherkin is offline
ZwipZwap Zapony
Junior Member
Join Date: Feb 2016
Old 11-09-2017 , 11:03   Re: Can't check if an argument is a specific string, "argument type mismatch"?
Reply With Quote #10

Quote:
Originally Posted by asherkin View Post
This is against our rules - you can attach the source code and log as files to your post rather than linking offsite if CloudFlare wont let you post them inline.
Please also use the Advanced Edit mode to mark your post as solved while you're in there uploading attachments.
I see. Sorry about that. Is it better now?
ZwipZwap Zapony 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 21:02.


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