callback?

  • I'm trying to create an economy/buy/sell system.

    this is my GUI so far


    as i am learning java the some documentation makes no sense to me. i understand i need to use callbacks for setting prices(player enters price clicks submit). i cant seem to wrap my head around how to set up call backs.

    would anyone feel friendly enough to give me a basic example? ive been watching videos but none of it makes sense to me. so sorry to ask so many questions!

  • I've tried to explain them a bit in this topic ;) RE: Player Animation's


    Basically the game is written with multiplayer in mind, so it consists of a server and the clients (even in singleplayer, you can think of it like an "integrated server"). Plugins are always executed on the server, so you can't get a result from a player immediately (because the server has to request that data from the client first). For instance, if you want to get the text from a text field (which only exists on the client), the server has to retrieve that data from the client first (or more precisely, there is a minor delay between the call and when the result is available). That's where callbacks are being used.


    A callback is basically like a "method" (containing your code) that gets executed once the server receives the result from the player. In this case, once the server received the text field text from the client, it invokes the callback method. For example:


    Java
    textField.getCurrentText(player, (String txt) -> {
        //This is your method body, i.e. the code that gets executed when the server gets the text.
    //The current text of the text field is stored in the "txt" parameter
    });


    The Java language features which are relevant in this case are anonymous classes and so called lambda expressions (you can find lots of information about these things on google) :)

  • red51 thank you for taking the time to give me a better explanation! And some help from yahgiggle i managed to get it working. for some reason tho, anytime i tried to code it using a lambda i would get an NPE on anything that had to do with the database(probably my lack of knowledge).


    im sure there is a cleaner way to do it but....





  • Nice UI 8):thumbup:

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!