Warning + A Question
#1

Hello all.
I get a warning which I know what it means but I dont know why I keep getting it:
pawn Code:
warning 211: possibly unintended assignment
Warn. line:
pawn Code:
if(reason = 0 && Finished[playerid] == 1) return Finished[playerid] = 1;
Please help.
+I have 2 questions:

1.is there any possible way to make all of this in 1 line:
pawn Code:
case 4..20: (---) case 24..30 (---) case 34..40  (---) case 44..50  (---) case 54..60
2.How can I make that if a variable has reached the number of 60 the player cant spawn anymore?

Thanks for help.
Reply
#2

Quote:
Originally Posted by nuriel8833
View Post
Hello all.
I get a warning which I know what it means but I dont know why I keep getting it:
pawn Code:
warning 211: possibly unintended assignment
Warn. line:
pawn Code:
if(reason = 0 && Finished[playerid] == 1) return Finished[playerid] = 1;
Please help.
+I have 2 questions:

1.is there any possible way to make all of this in 1 line:
pawn Code:
case 4..20: (---) case 24..30 (---) case 34..40  (---) case 44..50  (---) case 54..60
2.How can I make that if a variable has reached the number of 60 the player cant spawn anymore?

Thanks for help.
For the first question: You cant return like that, you should do it like this:
pawn Code:
if(reason = 0 && Finished[playerid] == 1)
{
     Finished[playerid] = 1;
     return 0;
}
Second question, its already on 1 line right..?

Last question:
When a player connects, add one to a variable (OnlinePlayers++. When a player disconnects remove one from it (OnlinePlayers++. When a player connect, check if On‌linePlayers == 60, and then kick the person or do something with him.
Reply
#3

pawn Code:
if( (reason == 0) && (Finished[playerid] == 1) ) return Finished[playerid] = 1;
And for the second question, no you cannot. It's because PAWN breaks the statement with the help of brackets.
Reply
#4

Quote:
Originally Posted by Wesley221
View Post
For the first question: You cant return like that, you should do it like this:
pawn Code:
if(reason = 0 && Finished[playerid] == 1)
{
     Finished[playerid] = 1;
     return 0;
}
Second question, its already on 1 line right..?

Last question:
When a player connects, add one to a variable (OnlinePlayers++. When a player disconnects remove one from it (OnlinePlayers++. When a player connect, check if On‌linePlayers == 60, and then kick the person or do something with him.
1.Still getting this warning (Edit: fixed by T0pAz,thanks a lot)
2.no,between those cases there is only case 21,case22,case23 etc.. I just made the code shorter.
3.Its not about OnPlayerConnect,its about OnPlayerSpawn
Reply
#5

I know, what you are talking about, Don't open directy .pwn file. Try to open it via opening Pawno folder first
Then open pawno.exe
Then open your script
Reply
#6

2. You mean:
pawn Code:
case 4..20:
{

}
case 24..30:
{

}
case 34..40:
{

}
case 44..50:
{

}
case 54..60:
{

}
Or..?

Edit:
3. Oh, my bad; thought it was to check for last VIP spots or something
Reply
#7

Quote:
Originally Posted by Wesley221
View Post
2. You mean:
pawn Code:
case 4..20:
{

}
case 24..30:
{

}
case 34..40:
{

}
case 44..50:
{

}
case 54..60:
{

}
Or..?

Edit:
3. Oh, my bad; thought it was to check for last VIP spots or something
Yes,I mean how to write all of them in 1 line like (I know its incorrect Im just giving an example:
pawn Code:
case 4..20,24..30,34..40,44..50,54..60:
Reply
#8

It's bad practise to write things all on one line. It looks very messy and can become confusing.

Compare:
pawn Code:
if(IsPlayerAdmin(playerid)) { pAdmin[playerid] = 1; } else { pAdmin[playerid] = 0; }
pawn Code:
if(IsPlayerAdmin(playerid))
{
    pAdmin[playerid] = 1;
}
else
{
    pAdmin[playerid] = 0;
}
Even though for this you should do:
pawn Code:
pAdmin[playerid] = IsPlayerAdmin(playerid);
But that's not relevant, I just couldn't think of another simple example.
Reply
#9

Quote:
Originally Posted by MP2
View Post
It's bad practise to write things all on one line. It looks very messy and can become confusing.

Compare:
pawn Code:
if(IsPlayerAdmin(playerid)) { pAdmin[playerid] = 1; } else { pAdmin[playerid] = 0; }
pawn Code:
if(IsPlayerAdmin(playerid))
{
    pAdmin[playerid] = 1;
}
else
{
    pAdmin[playerid] = 0;
}
Even though for this you should do:
pawn Code:
pAdmin[playerid] = IsPlayerAdmin(playerid);
But that's not relevant, I just couldn't think of another simple example.
Okay
now can someone answer question number 2?
Reply
#10

returning 0 on OnPlayerRequestSpawn() prevents the player from spawning. i would use a global variable, and then check if it equals to 60.

pawn Code:
public OnPlayerRequestSpawn(playerid)
{
    if(someVar == 60)
    {
        return 0;
    }
    // rest of the code here
    return 1;
}
Reply
#11

Quote:
Originally Posted by [Diablo]
View Post
returning 0 on OnPlayerRequestSpawn() prevents the player from spawning. i would use a global variable, and then check if it equals to 60.

pawn Code:
public OnPlayerRequestSpawn(playerid)
{
    if(someVar == 60)
    {
        return 0;
    }
    // rest of the code here
    return 1;
}
Okay thanks a lot 4 all of your help
+Rep for you all
Reply
#12

Quote:
Originally Posted by nuriel8833
View Post
Hello all.
I get a warning which I know what it means but I dont know why I keep getting it:
pawn Code:
warning 211: possibly unintended assignment
Warn. line:
pawn Code:
if(reason = 0 && Finished[playerid] == 1) return Finished[playerid] = 1;
Please help.
+I have 2 questions:

1.is there any possible way to make all of this in 1 line:
pawn Code:
case 4..20: (---) case 24..30 (---) case 34..40  (---) case 44..50  (---) case 54..60
2.How can I make that if a variable has reached the number of 60 the player cant spawn anymore?

Thanks for help.
The "unintended assignment" is
pawn Code:
reason = 0
Are you trying to assign the variable "reason" to the value of 0, or are you trying to compare it to 0? If the latter is the case, than you should use the logical comparison operator of '=='.

For your 1st question, my only suggestion would be to use the modulo operator (granted it may be a tad slower than what you had in mind):
pawn Code:
if(!(1 <= variable % 10 <= 3))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)