AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Solved ] prefix for a function. (https://forums.alliedmods.net/showthread.php?t=190137)

Aooka 07-15-2012 09:13

[ Solved ] prefix for a function.
 
Hello everyone, :crab:
I've an other question for today :)

So, I see a lot's of code like that :

Code:
public bool: MyFunction( id , ... ) { /* some code */ }

Code:
public Float: MyFunction( id , ... ) { /* some code */ }

Code:
public AwesomeFuction: MyFunction( id , ... ) { /* some code */ }

So me, when i do that it do not work a lot's ...
When i compil my code they are a terrible warning :cry:

Quote:

/tmp/textgWIKME.sma(65) : warning 213: tag mismatch
So why the other code works and mine not ? :cry:

Thanks all in advance héhé

jimaway 07-15-2012 09:19

Re: prefix for a function.
 
and whats the data type called 'AwesomeFuction' ?

<VeCo> 07-15-2012 09:19

Re: prefix for a function.
 
The returned value must be with the same tag.

Aooka 07-15-2012 09:21

Re: prefix for a function.
 
Quote:

and whats the data type called 'AwesomeFuction' ?
It's just an example ^^.

Quote:

The returned value must be with the same tag.
Thanks Veco but I do not understand exactly what you want to tell me :/

<VeCo> 07-15-2012 09:29

Re: prefix for a function.
 
Show your code.

YamiKaitou 07-15-2012 09:29

Re: prefix for a function.
 
If you tag a function as a bool, you must return a bool.

Aooka 07-15-2012 09:37

Re: prefix for a function.
 
Oh okay.

Here it's work :
Spoiler


And here it's do not work :
Spoiler


Edit: I understand when i return an integer i do bool: fution. a float, it's Float: Fuction.

YamiKaitou 07-15-2012 09:39

Re: prefix for a function.
 
If you are going to tag a function, use a valid tag and then return a value of that tag. The reason why it does not work is because you are returning an untagged value where you are declaring the function as returning a tagged value


Example:
PHP Code:

public CsTeam:getTeam(id)
{
    return 
cs_get_user_team(id);



Aooka 07-15-2012 10:21

Re: prefix for a function.
 
Oh! Okay. SO it's not good to use tag like a comment/sentence/text

Liverwiz 07-15-2012 10:44

Re: prefix for a function.
 
Quote:

Originally Posted by Aooka (Post 1750835)
Oh! Okay. SO it's not good to use tag like a comment/sentence/text

It is ok in the case where you'd want to return specific data types such as CsTeams, bool, Float, or even your defined data types. Its just like tagging a variable, but its tagging the return type. for instance......

PHP Code:

new bool:hasThing[33]

public function(
id)
{
    new 
bool:having
    having 
get_hasThing(id)
}

public 
bool:get_hasThing(id)
    return 
hasThing[id

Where as this code would not work if i were to take out the bool identifier in get_hasThing it would throw your tag mismatch warning. It is important if your functions must return specific data types.


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

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