Warning + A Question -
nuriel8833 - 02.02.2012
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.
Re: Warning + A Question -
Wesley221 - 02.02.2012
Quote:
Originally Posted by nuriel8833
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 OnlinePlayers == 60, and then kick the person or do something with him.
Re: Warning + A Question - T0pAz - 02.02.2012
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.
Re: Warning + A Question -
nuriel8833 - 02.02.2012
Quote:
Originally Posted by Wesley221
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 OnlinePlayers == 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
Re: Warning + A Question -
SampLoverNo123 - 02.02.2012
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
Re: Warning + A Question -
Wesley221 - 02.02.2012
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
Re: Warning + A Question -
nuriel8833 - 02.02.2012
Quote:
Originally Posted by Wesley221
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:
Re: Warning + A Question -
MP2 - 02.02.2012
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.
Re: Warning + A Question -
nuriel8833 - 02.02.2012
Quote:
Originally Posted by MP2
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?
Re: Warning + A Question -
[Diablo] - 02.02.2012
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;
}
Re: Warning + A Question -
nuriel8833 - 02.02.2012
Quote:
Originally Posted by [Diablo]
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
Re: Warning + A Question -
Tannz0rz - 02.02.2012
Quote:
Originally Posted by nuriel8833
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
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))