Solved getConfig().set(getConfig().getString("blabla"), ++)

Discussion in 'Plugin Development' started by PlazmaStorm, Jul 28, 2014.

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

    theguynextdoor

    A fair amount of lack of understanding, wrong/unknowledgeable suggestions and general lack of Java knowledge has been going around in this thread.

    The initial question pertained to simply incrementing a value in a config. This is obviously achieved by getting the value, then setting the value to the one fetched from the config.

    We currently have insufficient code to be able to tell how the current code is wrong and/or assist with a sufficient fix. As stonar96 stated it does appear you have, what we can only speculate as, a local variable.

    What is a local variable? Well besides the fact you should all know this anyway, a local variable is one which is defined in a subroutine, and is only usable by that subroutine. The value of which is set in the subroutine and is temporary. That variable and it's value is only around for when that subroutine is being used. Put another way, local variables won't persist through multiple method calls.

    We cannot tell if this is a per player value, of if it is suppose to be global for all the players on the server (assuming of course that it is a value relating to players). If that assumption is correct, and it is a value for players; then the use of a single global variable (i.e 1 int variable) could be used to relate as a total for all players on the server, or a Map could be used to hold the value of each player's 'clicks'.

    If you ask me, then I would personally recommend you do as above, instead of having to use the getConfig() method each time. I don't know how often this method of incrementing the clicks variable is, but it sounds (again another assumption) like it could be called a lot. Using getConfig() in itself is not bad, but you are constantly saving the config which each edit which means there could be a lot of I/O involved.

    I would also recommend you try and learn more Java before going too far, because you really should have known how the ++ operator works in the first place. If someone comes on the forums and posts a question and then copy and pastes the error that their IDE is showing them, then it is likely that person does not have sufficient Java knowledge.
     
    stonar96 likes this.
  2. Offline

    PlazmaStorm

    theguynextdoor , DigitalSniperz
    Thx a lot guys works great.
    again sorry theguynextdoor for all the trouble thx a lot again for helping
    stonar96
    I am already learning java but I havent done much yet
    Give me the best way to learn and I will if you have one
     
  3. Offline

    stonar96

    PlazmaStorm It's maybe not helpful for you, but I think the best way is school education, or learn from a person, which has a knowledge of Java. You should be also really interested in it, not just interested in how to code simple bukkit plugins. Once you can also understand the bukkit API, not just use it.

    I can also tell you how I learned it: I am now 18. When I was 14, I learned the basics of the programming language C in school and also a little bit assambly. These programming languages are very hardware-related and not object oriented like Java. But you also learn about how loops and if-statements, how to call functions, and so on. I also learned how this works on the hardware, what happens with the RAM, what is the stack, how does it all work on the hardware, so you get for example an idea how multithreading works (so you also get an idea about thread-savety). I know this all might not important for Java, but what I want to say is, that you can understand much things in java better if you know much about the basics. For example you can use pointers in C, Java does this automaticaly with all Objects (not with int, double, ...). At school we didn't make applications for the pc, we coded programms for Microcontrollers. I started Java programming because I was also interested in this language, later even more because of minecraft and bukkit. My brother learned 5 Years Java in his school and now he works as programmer. He teached me all the new stuff in Java and it was really easy for me. The big difference was, that I can now use Objects. And the rest of my Java knowledge I have gained by practice, trying new stuff (not just coding plugins), asking my brother or in forums (also Java basic questions if I had the feeling, that I didn't understand it), I watched many tutorials, and so on ...

    sry for my bad english ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    PlazmaStorm

    stonar96
    dont worry i can understand it it isnt that bad ;)
    I am 15 so i still have 3 years to learn from school and you might think i am not interested but i am and i am just getting a little over excited about knowing some basic and making me think i know so much ;)
    Sadly my school dosent teach computer science and any of the languages like java, javascript, c, c++, python... And no one in my familly is interested in computers so i dont have much chances to learn like you have.
    all the little knowledge i have was just me teaching myself and reading threads
    Any ways thx a lot to you all and the last two solutions worked so im fine
     
  5. Offline

    JoeyDevs

    Im on my mobile so i hope i types it good.


    int configint = getConfig().getInt("path.to.int");

    int configinsert = configint++;
    getConfig().set("path.to.value", configinsert);


    I cannot test or somthing cause im on mobile i hope this helped u
     
Thread Status:
Not open for further replies.

Share This Page