Integer does not update

Discussion in 'Plugin Development' started by TImewalkerZ, Sep 8, 2015.

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

    TImewalkerZ

    Hi, I am new to plugin development and just began yesterday.
    I have been experimenting around and made a plugin where you can sing to Spongebob's theme song.
    However, it does not seem to work. It does compile and run without a problem but when I do /startsong
    which is supposed to add 1 to the integer prog, I only get the reply and nothing is added to "prog".
    When I do /ayeayecaptain, it says do /startsong to begin your song, which only happens if prog == 0
    Can someone be kind to help a newb troubleshoot his plugin? ;3

    http://pastebin.com/XJLdN1rx
     
    Last edited: Sep 8, 2015
  2. Offline

    meguy26

  3. Offline

    TImewalkerZ

    @meguy26 Thank you for ur help. :)
    I have searched it up and just want to confirm.
    So do I just replace prog with this.prog?
     
  4. Offline

    Oxyorum

    @TImewalkerZ No. That won't work. The issue is that, at the moment, the value of prog will not be shared between your commands. Each invocation of the onCommand will have it's own prog variable (each time onCommand is called, a new prog variable will be made). The way to fix that is related to the scope of the prog variable.

    You should be able to figure this out by reading up more on variable scope, like recommended above.
     
  5. Offline

    TImewalkerZ

    @Oxyorum Can somebody help me solve the problem in my program first, please?:confused:

    Also, if the value of prog isn't transferred from a command to another, it shouldn't even compile as prog wouldn't have been defined. Help?


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Sep 8, 2015
  6. Offline

    Oxyorum

    @TImewalkerZ That's not what I meant. What I'm saying is that there will be a separate instance of the prog variable for each command, and those instances cannot share information with each other, so your code would never work as intended. To fix this, simply pull your prog variable outside of the onCommand method. This will ensure that all of your commands can access the variable and make changes to it.
     
    TImewalkerZ likes this.
Thread Status:
Not open for further replies.

Share This Page