Jump to content

Static field ...


Recommended Posts

Posted (edited)

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
Posted
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
Posted (edited)

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
Posted (edited)
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
Posted
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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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