What should this return
#1

Hey,

In the 8months that I have been scripting I have never worked out what I should return however I have this:

pawn Код:
public RapedDamage(playerid)
{
    new Float:H;
    new Float:X, Float:Y, Float:Z;
    if(PlayerIsInfected[playerid] == 1 && PlayerHasCured[playerid] == false) // HIV
    {
        SetPlayerHealth(playerid, GetPlayerHealth(playerid, H) - 5);
        return 1;
    }
    if(PlayerIsInfected[playerid] == 2 && PlayerHasCured[playerid] == false)
    {
        GetPlayerPos(playerid, X, Y, Z);
        SetPlayerPos(playerid, X, Y, Z+8);
        return 1;
    }
    if(PlayerHasCured[playerid] == true)
    {
        KillTimer(RapedTimer[playerid]);
        return 1;
    }
    return 1;
}
I think it should return 1 however as you can see I have return 1 for most things. Would this mean it should return 0??

Thanks,

-Snowman12.
Reply
#2

Quote:
Originally Posted by Snowman12
Посмотреть сообщение
I think it should return 1 however as you can see I have return 1 for most things. Would this mean it should return 0??

Thanks,

-Snowman12.
Return values may consist of true or false boolean literals, though this does not extend the purpose of return statements. https://sampwiki.blast.hk/wiki/Keywords:Statements#return
Reply
#3

@****** I'm using it in a command I can send it to you via PM if you wish.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Return values can be anything you like.
Quote:
Originally Posted by Gh05t_
though this does not extend the purpose of return statements.
....
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
....
Counteraction? You have misread me.

Quote:
Originally Posted by Gh05t_
Return values MAY consist of true or false boolean literals, though this does not extend the purpose of return statements.
I fail to see reason for your counteraction when I have not disagreed with your statement?

Also, assuming you have experiences with multiple languages, you understand return value assignment? The actual purpose of assigning true or false values?
Reply
#6

Gh05t_ I don't think you understand my meaning. Also "assuming" I'm pretty sure there is not a single thing you know - around scripting - that ****** hasn't created into a better way I have said it before and will again ****** is some what of a god when it comes to scripting.
Reply
#7

Quote:
Originally Posted by Snowman12
Посмотреть сообщение
Gh05t_ I don't think you understand my meaning. Also "assuming" I'm pretty sure there is not a single thing you know - around scripting - that ****** hasn't created into a better way I have said it before and will again ****** is some what of a god when it comes to scripting.
He is intelligent. He knows what he is doing. Though, having a discussion pertaining to this topic is relevant and I am free to express my opinion. I have yet to say what he has stated is incorrect, I'm not ignorant. Though your post rather shows ignorance. I am still learning, so are you, and so is ******. My post count and reputation matters not to me, though I do believe you judge me on these factors.

Quote:
Originally Posted by ******
thus the way I read it was that you were stating that returns were allowed to return booleans, even though they were capable of doing more.
though this does not extend the purpose of return statements. (usage of boolean literals is NOT the only purpose of the return statement is what I referring to).
Reply
#8

You need to set 'return true/false' only if you are using the value that you get from 'returns'.

Example:
pawn Код:
//Some stock: (It can be a callback too..)
stock DoSomethingTo(playerid)
{
    if(!IsPlayerConnected(playerid)) return false;

    SetPlayerBlaBla(...);
    SetPlayerOther(...);
    //...
   
    return true;
}

//In this case, the stock will return true after executing your functions
//and making changes to a player.
//If the player isn't connected, it returns false.


//Now, you can make use of the returned value:
if(!DoSomethingTo(targetplayer))  SendClientMessage(playerid, -1, "Sorry, the player isn't connected.");
else SendClientMessage(playerid, -1, "Changes has taken place successfully!");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)