SAMP wiki fails
#1

Maybe I'm idiot or maybe samp editors, but I think that they failed with one thing.So there is one lesson/script where is explained about else if function, they explaining it like this(i'll put their explaining here):
Код:
else if

An else if is a check which occurs if the first if check fails to check something else
So i did't agree with their explanation, which is marked like bold in the code.Because I have example in my script, and this is opposite for their explanation.I have perfectly working race code, so I will copy only the beggining of that:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	new string[100];
	format(string, sizeof(string), "Now you can start the race!!!", 1, 2);
	vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
	if(vehicle == 411)
	{
	cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2334.7681,-2179.3489,35.1945, -2143.2742,-2006.9039,95.0157, 9);
	cp[playerid] = 0;
	}
	else if(vehicle == 451)
	{
	cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2334.7681,-2179.3489,35.1945, -2143.2742,-2006.9039,95.0157, 9);
	cp[playerid] = 0;
	SendClientMessage(playerid, 0xFFFFFFFF, string);
	return 1;
	}
	return 0;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
	if (cp[playerid] == 0)
	{
	cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
	cp[playerid] = 1
	}
   	else if (cp[playerid] == 1)
   	{
   	cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
   	cp[playerid] = 2;
	}
	else if (cp[playerid] == 2)
	{
   	cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2474.9404,-2077.9385,124.7880, -2769.8372,-1811.5950,141.6222, 9);
   	cp[playerid] = 3;
}
Ok so how you see there are many if elses statements and by wiki, if the first if won't fail else if will be false and won't be executed.But how I said, my race is working and when I sit into cars infernus and turismo first cp will appear and if that's true, than when I will enter to this cp, another cp will appear with new co-ordinates.So you see that actually you can't trust even wiki, because i have like evidence for their lying... Simple explanation of what I wanted to say:that by wiki when if statement is true else if won't be exetuded and in my version although it is true, the else if statement will be executed!So may I not read correctly it, maybe you have some other version of this?If yes than write what you think about that-it'll be better for everyone, because more we know, more we can do!
Reply
#2

Check this:
pawn Код:
if(condition)
{
    // code if condition one was true
}
if(condition_2) // this will be executed since there's no return in the first condition
{
    // code if condition_2 was true
    return 1;
}
if(condition_3) // this will be executed ONLY if condition_2 was false, because condition_2 has a return
{
    // code if condition_3 was true
}
else if(condition_4) // this will be executed ONLY if condition_3 was false
{
    // code if condition_4 was true
}
if(condition_5) // this will be executed after condition_4
{
    // code if condition_5 was true
}
else if(condition_6) // this will be executed if condition_5 was false
{
    // code if condition_6 was true
}
else if(condition_7) // this will be executed if condition_6 was false
{
    // code if condition 7 was true
}
else // this will be executed if none of the THREE conditions (5, 6 and 7) above were true
{
    // code if none of the THREE above were true
}
Reply
#3

I didn't think that you read what i wrote, because you put there an explanation, which in the fact the same like in SAMP wiki.Read first my first post in the thread.By my case, if condition is true and that means by you and wiki, that else if statement won't be executed, so by me it is executed, so there is three words explaining this shit-wtf?!Maybe our pawno programs is different?
Reply
#4

I think you are misunderstanding something.

cp[playerid] is changing in your script.

If you enter the first checkpoint, then cp[playerid] is 0, so first if is true and other else if's won't be executed.

pawn Код:
if (cp[playerid] == 0) // true
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
    cp[playerid] = 1
}
else if (cp[playerid] == 1) // won't be called
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
    cp[playerid] = 2;
}
But if you enter second checkpoint, then cp[playerid] is 1, so first is false and it takes the next else if.

pawn Код:
if (cp[playerid] == 0) // false
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
    cp[playerid] = 1
}
else if (cp[playerid] == 1) // true
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
    cp[playerid] = 2;
}
Reply
#5

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[100];
    format(string, sizeof(string), "Now you can start the race!!!", 1, 2);
    vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
    if(vehicle == 411)
    {
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2334.7681,-2179.3489,35.1945, -2143.2742,-2006.9039,95.0157, 9);
    cp[playerid] = 0;
    }
    else if(vehicle == 451)
    {
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2334.7681,-2179.3489,35.1945, -2143.2742,-2006.9039,95.0157, 9);
    cp[playerid] = 0;
    SendClientMessage(playerid, 0xFFFFFFFF, string);
    }
    return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
    if (cp[playerid] == 0)
    {
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
    cp[playerid] = 1
    }
    else if (cp[playerid] == 1)
    {
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
    cp[playerid] = 2;
    }
    else if (cp[playerid] == 2)
    {
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2474.9404,-2077.9385,124.7880, -2769.8372,-1811.5950,141.6222, 9);
    cp[playerid] = 3;
        }
        return 1;
}
Reply
#6

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
I think you are misunderstanding something.

cp[playerid] is changing in your script.

If you enter the first checkpoint, then cp[playerid] is 0, so first if is true and other else if's won't be executed.

pawn Код:
if (cp[playerid] == 0) // true
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
    cp[playerid] = 1
}
else if (cp[playerid] == 1) // won't be called
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
    cp[playerid] = 2;
}
But if you enter second checkpoint, then cp[playerid] is 1, so first is false and it takes the next else if.

pawn Код:
if (cp[playerid] == 0) // false
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2143.2742,-2006.9039,95.0157, -2145.5430,-1958.8540,117.9665, 9);
    cp[playerid] = 1
}
else if (cp[playerid] == 1) // true
{
    cp[playerid] = SetPlayerRaceCheckpoint(playerid, 0, -2145.5430,-1958.8540,117.9665, -2474.9404,-2077.9385,124.7880, 9);
    cp[playerid] = 2;
}
So you don't understand yourself Because you saying that, when you enter into first cp it will become true and than cp1 won't be called, but after that it will anyway appear-so that's what you saying lol And I think now if you reading this post, you understand that your explanation is bullshit So how by you second checkpoint can appear if like you saying first checkpoint is true and by that else if is false?And theoretically if that it is than if else WILL NOT BE EXECUTED, so I think you now understand that won't executed means won't work.In conclusion the second cp(cp1) can't appear, but it's appear by my code.
Reply
#7

Second cp is false ONLY in the FIRST TIME. If you enter the checkpoint SECOND TIME, it is true, and first is false.
Reply
#8

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Second cp is false ONLY in the FIRST TIME. If you enter the checkpoint SECOND TIME, it is true, and first is false.
But how it could be FIRST TIME,SECOND TIME?!There's only one time and if it fails than no second checkpoint will appear and you can't enter if there is no cp...And by the way, how you can enter cp twice lol?When you enter to it it will disappear.
Reply
#9

The Wiki information is correct in this instance.

It states that if the first if check is false, only then will it continue on to check the else if.
If the first if check is true, then the else if will not be called at that time.

However I think you're being confused, this does not retain for the next time the piece of code is called, the process will happen each time the code is called. Therefore MadeMan's example is in fact completely correct.
Reply
#10

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The Wiki information is correct in this instance.

It states that if the first if check is false, only then will it continue on to check the else if.
If the first if check is true, then the else if will not be called at that time.

However I think you're being confused, this does not retain for the next time the piece of code is called, the process will happen each time the code is called. Therefore MadeMan's example is in fact completely correct.
But please, can you then explain this case, how it can be?Because my code is working, but it shouldn't be by the wiki, because first if is true, so else if won't be executed...I'm so depressed because of that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)