How to increase something by x number?
#1

Ok, so I have the below code, and actually several places in my entire code where I would like to increase something by [number], but I just cant figure out how its done, I am sure its something simple, but I have just not figured it out.

I get the error "warning 215: expression has no effect" on this line "ServerHours+number;"
it works fine if I have "ServerHours++;" but how would I go about doing something like "ServerHours+10;"
or as in my code below where I can type in the hours I want to increase the time by.

pawn Код:
//========================================[Increase world time]=========================================
YCMD:time(playerid, params[], help)
{
    if (help)
    {
        SendClientMessage(playerid, 0xFF0000AA, "Increases time by [number] hours");
    }
    else
    {
        if (IsPlayerAdmin ( playerid )) // If the player is logged into RCON
        {
            new number;
            if(sscanf(params,"n", number))return SendClientMessage(playerid, 0xFF0000AA, "Numbers only!");
            ServerHours+number;
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000AA, "Admin only command");
        }
    }
    return 1;
}
Thanks!
Reply
#2

Instead of giving him a riddle can't you just tell him?
pawn Код:
var += 10; // Adds 10
Reply
#3

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
var += 10; // Adds 10
Although that was a funny comment to read, Icognito is trying to help him in the long run in understanding pawno. Althouh harder for the OP, it will make him better at understanding the language.

EDIT: Icognito posted while i was posting ..
EDIT2: MP2 removed his funny comment as i quoted it.
Reply
#4

Instead of giving him a riddle, I told him what to do, so now he knows. He won't ask again unless he forgets.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
You are right in that it is simple, but I believe there's a gap in your thinking. You do "ServerHours + number", but then what happens to the result? You are doing a sum but what happens to the answer? That's what you need to think about. Forget about variables and just think about what this does:

pawn Код:
5 + 7
Yeah, I just figured since "++" increases something by one, "+ number" would increase it by that number.

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
var += 10; // Adds 10
And this is what I was missing, thanks!
This will make my code a few lines shorter >_>
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
Instead of giving him a riddle, I told him what to do, so now he knows. He won't ask again unless he forgets.
Icognito is meaning to say that is all fair and well, but if you told him how it works, he will understand it alot better rather than just the answer. If he understands it, he will never ask for help on this subject again. Usually.
Reply
#7

It's ****** not Incognito.

He does understand it. += value adds the value to the variable - there's nothing to understand.

I do agree 'spoon-feeding' people information isn't the best, but I feel this time doesn't count.

EDIT: In direct response to ******' post:


Quote:
Originally Posted by ******
Посмотреть сообщение
what does that teach them?
It teaches them the operator and how to use it.

Quote:

teach
Verb:
Show or explain to (someone) how to do something: "she taught him to read".

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)