SA-MP Forums Archive
Stock help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Stock help (/showthread.php?tid=274741)



Stock help - Godhimself - 07.08.2011

Ok im trying to make a simple stock thats returns the players health in a float.

Heres the stock:

pawn Код:
stock GetHealth(playerid)
{
    new Float:pHealth;
    GetPlayerHealth(playerid, pHealth);
    return pHealth;//Line 96
}
And here is the error:

Код:
(96) : warning 213: tag mismatch
Any help?

Thanks in advanced.


Re: Stock help - dowster - 07.08.2011

i didn't get a tag mismatch, are you using the latest compiler?


Re: Stock help - Grim_ - 07.08.2011

Your function is returning a float value, so you need it to be able to do so by adding the Float: tag in front of the function.
pawn Код:
stock Float:GetHealth(playerid)
{
    new Float:pHealth;
    GetPlayerHealth(playerid, pHealth);
    return pHealth;//Line 96
}



Re: Stock help - [L3th4l] - 07.08.2011

Try:
pawn Код:
stock GetHealth(playerid)
{
    new Float:pHealth;
    GetPlayerHealth(playerid, pHealth);
    return _:pHealth;//Line 96
}



Re: Stock help - Godhimself - 07.08.2011

Thankyou for you assistance guys.

@ Grim_

Thanks dude but that shows,

Код:
(94) : warning 208: function with tag result used before definition, forcing reparse
@ [L3th4l]

My god that compiled Thankyou. Please explain in detail line 96

Код:
return _:pHealth;
1. What is the meaning of return_?
2. When and why is return_ used?

Thanks in advanced.


EDIT: +1 Rep [L3th4l] for a spot on, fast response. Thanks again.


Re: Stock help - Grim_ - 07.08.2011

The _: makes the variable tag-less. Originally you were returning a float tagged variable, by adding the _: tag (which is equivalent to no-tag) it removes the tag and converts the value to an integer in this situation.


Re: Stock help - [L3th4l] - 07.08.2011

Check this: Click


Re: Stock help - Godhimself - 07.08.2011

Quote:
Originally Posted by Grim_
Посмотреть сообщение
The _: makes the variable tag-less. Originally you were returning a float tagged variable, by adding the _: tag (which is equivalent to no-tag) it removes the tag and converts the value to an integer in this situation.
Thankyou, i think i understood that.

Is this what you mean?:

I get the players health and save it to a float.
When i try to return that float, it results in a tag mismatch due to it being a float, and it cant just return a float?
You need to return it as a tagless, so it bypasses the float, and returns the float as a integra with the players health?