Returning Float in function
#1

Good evening, ok, so I wanted to create a function which is detecting on which degree is player aiming, so I found the way to create it with sin and cos, but when I am trying to return a float of angle I get warning. So I did it in two versions I will post both but I don`t know what is problem, in both is same warning:

PHP код:
stock GetPlayerAimingPoint(playeridFloat:Angle)
{
    new 
Float:XFloat:YFloat:Z//Float:Angle;
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridAngle);
    
+= (floatsin(-Angledegrees));
    
+= (floatcos(-Angledegrees));
    return 
Angle;//Warning Line
}
//Version 2
stock GetPlayerAimingPoint(playeridFloat:Angle)
{
    new 
Float:XFloat:YFloat:Z//Float:Angle;
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridAngle);
    
+= (floatsin(-Angledegrees));
    
+= (floatcos(-Angledegrees));
    return 
Float:Angle;//warning Line

Warning:
Код:
warning 213: tag mismatch
Reply
#2

PHP код:
stock Float:GetPlayerAimingPoint(playeridFloat:Angle

    new 
Float:XFloat:YFloat:Z//Float:Angle; 
    
GetPlayerPos(playeridXYZ); 
    
GetPlayerFacingAngle(playeridAngle); 
    
+= (floatsin(-Angledegrees)); 
    
+= (floatcos(-Angledegrees)); 
    return 
Angle;

Reply
#3

Quote:
Originally Posted by Banana_Ghost
Посмотреть сообщение
PHP код:
stock Float:GetPlayerAimingPoint(playeridFloat:Angle

    new 
Float:XFloat:YFloat:ZFloat:Angle
    
GetPlayerPos(playeridXYZ); 
    
GetPlayerFacingAngle(playeridAngle); 
    
+= (floatsin(-Angledegrees)); 
    
+= (floatcos(-Angledegrees)); 
    return 
Angle;

Bro, why should I create Angle variable, which I have defined in header of function?
Reply
#4

Quote:
Originally Posted by Sanady
Посмотреть сообщение
Bro, why should I create Angle variable, which I have defined in header of function?
Assign the float tag to the function. That's all.

------------

You should make it a public function if you get a reparse error/warning.
Reply
#5

Quote:
Originally Posted by Sanady
Посмотреть сообщение
Bro, why should I create Angle variable, which I have defined in header of function?
Ah fuck I was removing your comments and I didn't even notice it D:. Either way edited it.

Also do what SickAttack said.
Reply
#6

But why should I do that? I am planing using that function only two times...
Reply
#7

Quote:
Originally Posted by Sanady
Посмотреть сообщение
But why should I do that? I am planing using that function only two times...
You have to do that if you want the function to return a float...

If you want the function to assign the value to a variable/array passed by reference, then add "&" without the double quotes to the variable/array passed by reference in the function's arguments.

The function will then be used the same way as GetPlayerHealth, for example.

About the reparse error/warning, only do it if you get the error...
Reply
#8

Quote:
Originally Posted by Sanady
Посмотреть сообщение
But why should I do that? I am planing using that function only two times...
You don't have to, but if I remember correctly, if you tag a function, it'll throw either a warning or an error if it isn't located above what you're calling the function in. Either way is fine though.

EDIT: just tested, throws warning 208. So either relocate the function to above where you're using it or forward it.
Reply
#9

Probably I will forward it, like you and SickAttack said before, so I will try out.
Reply
#10

Working fine, ty, I reped both ^_^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)