简体   繁体   English

作业的左侧必须是变量

[英]The left-hand side of an assignment must be a variable

I have an issue I believe it may be a simple fix but I am currently stuck. 我有一个问题,我相信这可能是一个简单的解决方法,但是我目前仍然无法解决。

I have tried looking around but couldn't find anything helpful. 我尝试环顾四周,但找不到任何帮助。

This is my error: The left-hand side of an assignment must be a variable 这是我的错误:作业的左侧必须是变量

代码错误图片也在这里

This is my code: 这是我的代码:

} else if (token.equals("character-rights")) {
        player.getRights().ordinal() = Integer.parseInt(token2);


    public enum PlayerRights {

    PLAYER(true, true, true, true, false, 60),
    MODERATOR(true, true, true, true, false, 0),
    ADMINISTRATOR(false, false, false, false, false, 0),
    DEVELOPER(true, true, true, true, true, 0),
    DONATOR(true, true, true, true, true, 10);

    private boolean canTrade, canDuel, canPk, canSell, debugMode;
    private int yellTimer;

    private PlayerRights(boolean canTrade, boolean canDuel, boolean canPk, boolean canSell, boolean debugMode, int yellTimer) {
        this.canTrade = canTrade;
        this.canDuel = canDuel;
        this.canPk = canPk;
        this.canSell = canSell;
        this.debugMode = debugMode;
        this.yellTimer = yellTimer;
    }

    private static final ImmutableSet<PlayerRights> STAFF = Sets.immutableEnumSet(ADMINISTRATOR, DEVELOPER);
    private static final ImmutableSet<PlayerRights> MEMBERS = Sets.immutableEnumSet(MODERATOR, ADMINISTRATOR, DEVELOPER, DONATOR);
    private static final ImmutableSet<PlayerRights> NORMAL = Sets.immutableEnumSet(PLAYER, DONATOR);

    public boolean isStaff() {
        return STAFF.contains(this);
    }

    public boolean isMember() {
        return MEMBERS.contains(this);
    }

    public boolean isPlayer() {
        return NORMAL.contains(this);
    }

    public boolean canTrade() {
        return canTrade;
    }

    public boolean canDebug() {
        return debugMode;
    }

    public boolean canSell() {
        return canSell;
    }

    public boolean canDuel() {
        return canDuel;
    }

    public boolean canPk() {
        return canPk;
    }

    public int getYellTimer() {
        return yellTimer;
    }

}

and

public PlayerRights playerRights;

public PlayerRights getRights() {
    return playerRights;
}

The top code is where the error takes place. 上面的代码是发生错误的地方。 I would really appreciated some help, would make my day. 我将非常感谢您的帮助,这将使我过得愉快。

Enums are immutable. 枚举是不可变的。 You need to reassign a new enum value instead of writing things like 您需要重新分配一个新的枚举值,而不是编写类似

myEnum.ordinal() = 0;

You have to write a switch statement to check what Integer.parseInt(token2) is, and use the setRights method. 您必须编写一个switch语句来检查Integer.parseInt(token2)是什么,然后使用setRights方法。

switch (Integer.parseInt(token2)) {
    case 0:
        player.setRights(PlayerRights.PLAYER);
        break;
    case 1:
        player.setRights(PlayerRights.MODERATOR);
        break;
    case 2:
        player.setRights(PlayerRights.ADMINISTRATOR);
        break;
    case 3:
        player.setRights(PlayerRights.DEVELOPER);
        break;
    case 4:
        player.setRights(PlayerRights.DONATOR);
        break;
}

If your player class does not have a setRights method, you should probably add one. 如果您的player类没有setRights方法,则可能应该添加一个。

You need to add the following method to the class (Player?) that contains public PlayerRights getRights() : 您需要将以下方法添加到包含public PlayerRights getRights()的类(Player?)中:

public void setRights(PlayerRights rights) {
  this.playerRights = rights;
}

Now, call this setter method in the line you have in the screen shot: 现在,在屏幕快照所在的行中调用此setter方法:

player.setRights(PlayerRights.values()[Integer.parseInt(token2)];

Be ready to catch an array-out-of-bounds exception for wrong input. 准备捕获错误输入的边界超出数组异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM