Small bit of confusion...

Discussion in 'Plugin Development' started by TheChinski, Oct 9, 2012.

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

    TheChinski

    Heya all,

    Been trying to figure out why this doesn't work:

    Code:java
    1. String pie = e.getTo().getBlockX() + "," + ((e.getTo().getBlockY())-1) + "," + e.getTo().getBlockZ();
    2. String tart = templatefile.getString("" + (number-1));
    3. if(pie == tart) {
    4. player.sendMessage("&4Please don't go two up when laying a track. Thankyou.");
    5. e.setCancelled(true);
    6. return true;
    7. }


    When pop and tart are viewed in player.sendMessage etc. they come up the same, so I can't figure out why I don't get the Please don't go up two message? :/ The code is meant to stop a player moving up two spaces on the Y axis in a row without them moving on the X/Z axis, as its for a mine cart plugin, and tracks can only go one up at a time :)

    Thanks
     
  2. Could you atleast provide the whole function where this is in, we can't do anything with this...
     
  3. Offline

    Courier

    You can't use == to compare strings, it can return false even if the strings have the exact same characters. You need to use string1.equals(string2)
     
    TheChinski likes this.
  4. Offline

    Dave_

    try
    Code:
    if(pie.equalsIgnoreCase(tart)) {
    instead of

    Code:
     if(pie == tart) {
    EDIT: your practicing bad conventions. a variable should look like helloWorld or dankPlugin you are likely to get confused when you plugin gets large using variables with random names like that.
     
    TheChinski likes this.
  5. Offline

    TheChinski

    That was it. :)

    I'm new to Java, and this is only like my third plugin, so i'm still not completely familiar with these things. Thanks all! :D
     
Thread Status:
Not open for further replies.

Share This Page