Invalid AssignmentOperator?

Discussion in 'Plugin Development' started by ibWill, Jul 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ibWill

    Hello, I am getting this error: Syntax error on token "<", invalid AssignmentOperator Can someone please help?
    Code:java
    1. int j,i;
    2. for (Iterator<Player> localIterator = Players.iterator(); localIterator.hasNext(); i < j){
    3. Player p = (Player)localIterator.next();
    4. Player[] arrayOfPlayer;
    5. j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length; i = 0; continue; Player pl = arrayOfPlayer[i];
    6. p.showPlayer(pl);
    7.  
    8. i++;
    9. }[/i]
     
  2. Offline

    adam753

    The 3rd argument in a for loop should be something that is executed each loop, most likely i++. What you've got there now, i < j, is a boolean expression, so there's no point doing it each loop because there's nothing there to do. I assume what you wanted is for i<j to be part of the condition for it to continue, which is the second argument.
     
  3. Offline

    ibWill

    So what do you suggest i do, adam753 ?
     
  4. Offline

    adam753

    It depends, what are you trying to achieve?
     
  5. Offline

    ibWill

    adam753 , Ok so im making a plugin that when you right click with a clock, everyone vanishes
     
  6. Offline

    Tirelessly

    localIterator.hasNext() && i <j;
     
  7. Offline

    adam753

    So you're trying to go through every player stored in a list called Players, right? Here's a much easier way to iterate over a list than using that iterator nonsense:
    Code:
    for(Player p : Players) {
     
    }
    
     
  8. Offline

    ibWill

    ok lemme try that

    adam753, Now i get an unreachable code error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    adam753

    Unreachable code where? Can I see all the code in this method, please?
     
  10. Offline

    ibWill

    Code:java
    1. public void onDisable()
    2. {
    3. int j;
    4. int i;
    5. for (Iterator<Player> localIterator = Players.iterator(); localIterator.hasNext(); i < j){
    6. Player p = (Player)localIterator.next();
    7. Player[] arrayOfPlayer;
    8. j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length; i = 0; continue; Player pl = arrayOfPlayer[I];[/I]
    9. [I] p.showPlayer(pl);[/I]
    10.  
    11. [I] i++;[/I]
    12. [I] }[/I]
    13.  
    14. [I] Players.clear();[/I]
    15. [I] Antispam.clear();[/I]
    16. [I] }[/I]


    adam753, There's my code

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    adam753

    Isn't this exactly the same as at the start of the thread? Start by replacing line 5 with:
    Code:
    for(Player p : Players) {
    
    And where is the unreachable code?
     
  12. Offline

    ibWill

    Now i get the unreachable code error
    Code:java
    1. public void onDisable()
    2. {
    3. int j;
    4. int i;
    5. for (Player p : Players){
    6. Player[] arrayOfPlayer;
    7. j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length; i = 0; continue; Player pl = arrayOfPlayer[i];
    8. p.showPlayer(pl);
    9.  
    10. i++;
    11. }[/i]
     
  13. Offline

    adam753

    Code:
    j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length; i = 0; continue; Player pl = arrayOfPlayer[i];
    
    Okay.. Why do you have "continue" in there? You're doing several lines on one line there, and one of those things is "continue", which makes the loop stop this iteration and go onto the next one, so anything after "continue" won't be done. Why are you doing so many things on one line?
     
  14. Offline

    ibWill

    ok that helps me, adam753, but now do i just do an if statement to keep the loop going?
     
  15. Offline

    adam753

    What do you mean? The loop will keep going by itself. The code inside the loop will be run for each player in the list, and each time the variable "p" will be the next player in the list.
     
  16. Offline

    ibWill

    adam753, ok but now it says int j is never used
     
  17. Offline

    adam753

    You're trying to make every player visible to every other player, right? You would need two loops. An outside one to loop through every player, and an inside one to show every player to them.
    Code:
    for(Player p1 : bukkit.getOnlinePlayers()) {
        for(Player p2 : bukkit.getOnlinePlayers()) {
            p1.showPlayer(p2);
        }
    }
    
    It seems like you don't understand the code you've given me. It looks like you're new to Java, which is understandable, but you should really stick to simple steps before you go trying to write what you showed me earlier.
     
Thread Status:
Not open for further replies.

Share This Page