Stock help
#1

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.
Reply
#2

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

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
}
Reply
#4

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

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.
Reply
#6

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.
Reply
#7

Check this: Click
Reply
#8

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?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)