AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved How to convert "const String:var[]" to new syntax (https://forums.alliedmods.net/showthread.php?t=301706)

popey456963 10-01-2017 21:45

How to convert "const String:var[]" to new syntax
 
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?

Mitchell 10-01-2017 22:10

Re: How to convert "const String:var[]" to new syntax
 
const char[] className should work fine unless you have a mistake some where else in the code that you're not posting.

WildCard65 10-02-2017 09:42

Re: How to convert "const String:var[]" to new syntax
 
What's the declaration of "that"

shavit 10-02-2017 10:53

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

return Client_HasWeapon(view_as<int>(that), weapon);
?

sdz 10-02-2017 11:09

Re: How to convert "const String:var[]" to new syntax
 
they're* asking what is that is that being initialized to

shavit 10-02-2017 12:39

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

Originally Posted by EasSidezz (Post 2552105)
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.

WildCard65 10-03-2017 11:56

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

Originally Posted by shavit (Post 2552127)
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

Peace-Maker 10-03-2017 14:07

Re: How to convert "const String:var[]" to new syntax
 
Looks like smlib's function isn't returning a bool while your method is.

Mitchell 10-03-2017 14:28

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

Originally Posted by Peace-Maker (Post 2552365)
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

popey456963 10-03-2017 18:08

Re: How to convert "const String:var[]" to new syntax
 
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.


All times are GMT -4. The time now is 07:31.

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