Jump to content

Static field ...


dokato

Recommended Posts

Hi,

I'got a question about static fields in my Main script.
Does it become like a singleton for all my bot instances? Like if I start up multiple bot clients, will the value of a static field be always the same for all of these bot clients, even if the value gets modified at runtime? Or not?
I could test it myself ofc. but I don't have VIP atm and cannot run multiple bots...

I thought that a static field is same for the entire JVM, thats why I'm asking.

Thanks in advance.

Edited by dokato
Link to comment
Share on other sites

4 hours ago, Czar said:

Statics will be shared clientside with bot tabs, so all tabs are within the same scope, iirc.

Does that mean If I use static booleans in my GUI and someone opens 10 of the same script on 1 client, All 10 will be affected?
Is this why we use Getters and Setters? Whats the point of even having static fields then...?

  • Like 2
Link to comment
Share on other sites

Yep, getters and setters are for instances

Statics are good for their own reasons, e.g. global variables such as constants, e.g. declaring an entire class called ItemIDLibrary.java and filling it up with item id variables:

public static final int ABYSSAL_WHIP = 4151;
public static final int ARMADYL_GODSWORD = 11694;

whereas non-static helps with object oriented design, helps with memory usage, variables can be re-assigned and more productive code can be designed. They are both used in conjunction, not so much exclusively

Edited by Czar
  • Like 2
  • Mald 1
Link to comment
Share on other sites

17 hours ago, dokato said:

Ok and what if i open up multiple bot windows? (Instead of just one window with multiple tabs)

I think the point is, If you only use statics for what they are intended for, Whilst using proper Object Orientated Design principles, then you wont have to worry about these issues of " what if I use multiple Bot windows instead ".:gnome:

Edited by Elixar
  • Like 1
Link to comment
Share on other sites

5 hours ago, Elixar said:

I think the point is, If you only use statics for what they are intended for, Whilst using proper Object Orientated Design principles, then you wont have to worry about these issues of " what if I use multiple Bot windows instead ".:gnome:

Hahah, I understand that lol but i wanted to just know u know.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...