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

Solved How to convert "const String:var[]" to new syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
popey456963
Member
Join Date: Mar 2016
Old 10-01-2017 , 21:45   How to convert "const String:var[]" to new syntax
Reply With Quote #1

Just started using smlib, following function:

Code:
stock Client_HasWeapon(client, const String:className[])
When adding it to my methodmap (which uses the new syntax), I try the following:

Code:
	public bool has_weapon(const char[] weapon) {
		return Client_HasWeapon(that, weapon);
	}
However, the compiler complains of "tag mismatch". What is the right want to represent it with the new syntax?

Last edited by popey456963; 10-04-2017 at 12:18.
popey456963 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-01-2017 , 22:10   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #2

const char[] className should work fine unless you have a mistake some where else in the code that you're not posting.
Mitchell is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-02-2017 , 09:42   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #3

What's the declaration of "that"
__________________
WildCard65 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-02-2017 , 10:53   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #4

Code:
return Client_HasWeapon(view_as<int>(that), weapon);
?
__________________
retired
shavit is offline
sdz
Senior Member
Join Date: Feb 2012
Old 10-02-2017 , 11:09   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #5

they're* asking what is that is that being initialized to

Last edited by sdz; 10-02-2017 at 11:09.
sdz is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-02-2017 , 12:39   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #6

Quote:
Originally Posted by EasSidezz View Post
they're* asking what is that is that being initialized to
WildCard65's and my replies are just okay for that purpose.
WildCard65's advice would make OP realize that that is in fact not an int therefore throw a "tag mismatch" warning, and mine was to reference to that as in int.
__________________
retired
shavit is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-03-2017 , 11:56   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #7

Quote:
Originally Posted by shavit View Post
WildCard65's and my replies are just okay for that purpose.
WildCard65's advice would make OP realize that that is in fact not an int therefore throw a "tag mismatch" warning, and mine was to reference to that as in int.
While, your advice is helpful and could potentially be the solution to the warning, I was just asking out of curiosity more so then as a "hey, maybe you should check". By having the declaration of "that" posted would help us determine the TRUE and appropriate solution as here's the list of potential reasons:
  • "that" is not an int
  • Compiler bug
__________________
WildCard65 is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 10-03-2017 , 14:07   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #8

Looks like smlib's function isn't returning a bool while your method is.
__________________
Peace-Maker is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-03-2017 , 14:28   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #9

Quote:
Originally Posted by Peace-Maker View Post
Looks like smlib's function isn't returning a bool while your method is.
Hmm however it does return a boolean. Could old syntax do that without the right return type?
https://github.com/bcserv/smlib/blob...ents.inc#L1358
Mitchell is offline
popey456963
Member
Join Date: Mar 2016
Old 10-03-2017 , 18:08   Re: How to convert "const String:var[]" to new syntax
Reply With Quote #10

For reference, I had the following code:

Code:
#define that view_as<int>(this)
Since I somewhat dislike the `view_as<int>(this)` line and I'm used to using `that` a lot in JavaScript (at least, until arrow functions become more widespread). I imagine it is a bug with `smlib` where it doesn't include the return type `boolean`, but it does seem to return anyway.

Last edited by popey456963; 10-03-2017 at 18:09.
popey456963 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 04:58.


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