How to switch a lever?

Discussion in 'Plugin Development' started by TechGuard, Jul 14, 2011.

Thread Status:
Not open for further replies.
  1. PHP:
    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                        public 
    void run(){
                                
    byte data lever.getData();
                                if((
    data 0x8) != 8){
                                  
    data |= 8;
                                }
                                else
                                if((
    data 0x8) == 8){
                                  
    data ^= 8;
                                }
                                
    lever.setData((byte)data);
                        }
                    }, 
    0L);
    That code doesn't seem to work, and i'm 100% sure it is a lever block.
     
  2. What does |= do? Is that divide?
     
  3. Offline

    Hretsam

    Its an Bitwise operator meaning 'OR'

    OnTopic: i cant be much of help, as i'm terrible with bitwise operators. They never seem to work right with me...
     
  4. I've never played around with bytes, thanks :D
     
  5. If you simply want to toggle it (change the state no matter if it's on or not), you don't need that much code.
    An exclusive OR (^) on the correct bit would be enough.
    Code:
    data = data ^ 0x8;
    However, I rather think the problem is that setData() doesn't update the state.
    I read through a thread about that not long ago (don't have a link right now). I think you have to use another method to make the change take effect and also update its redstone functionality.

    EDIT: And why do you use the Scheduler if there's no delay btw?
     
Thread Status:
Not open for further replies.

Share This Page