Thread: [Info request: java] This vs That

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 [Info request: java] This vs That 
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Is it better to either:
    create a class in memory via
    Code:
    Classname nickname = new Classname(player);
    for each player - the advantage of this is you can then store public/private non static values in there
    OR
    is it better to have a class with static voids(the specified player in argument) to set values to the player - meaning a class isnt created for each player, they all use this static void in this class.

    Also, when initializing a class for a player, am I right in thinking a new class is created for the player each time this code is processed, OR does java intelligently check if this class has already been 'made' (-same as initialized?) for this player, and then use that? (classname nickname = new classname(args))


    Main question;

    Code:
    SettersClass setter = new SettersClass(player);
    getPlayer().getSettersClass().setVar(int);
    ^ class for each player.

    surely

    Code:
    getWorld().getSettersClass().setVarForPlayer(player, int);
    would be more stable as there only 1 class compared to 1 per player?

    Origional post:
    [SPOIL]Now, my main question. Is one method of ... the following void better than the other?

    If, in this class (called Classname) there is a void like this:

    Code:
    public void setVariable(int variable) {
      player.variable = variable;
    }
    IS IT BETTER, in your opinion, to have a STATIC VOID which ALL PLAYERS use to set the variable in question?

    By this I mean, is the above (where that class is constructed for each player, and they reference the void in the class the server's made for them) BETTER than using the following void, a void in this class which is GLOBAL to all players, like they all reference to this one class and use this void to set the var.

    Code:
    public static void setVariable(final Player player, int variable) {
       player.variable = variable;
    }
    [/SPOIL]


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Bump yo..


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Sep 2011
    Posts
    100
    Thanks given
    5
    Thanks received
    5
    Rep Power
    29
    I dont fully understand your first question but if you mean when an new variable is made does JVM look for an exact same variable and use that then no it doesn't(as far as I know). For me I think the code would look nicer if it was just like:

    Code:
    player.setRights(2);
    Instead of:

    Code:
    Player.setRights(player, 2);
    Although performance wise I have no idea.
    Reply With Quote  
     

  4. #4  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,886
    Thanks given
    1,860
    Thanks received
    4,732
    Rep Power
    5000
    1. Depends on your server, usually incoming frames are loaded into an array once
    2. You are using setters wrong, setters are used to set values for private variables inside the class the setter is in. If you want to change a value of the player, you should use something like nickname.getPlayer().setVariable(123);



    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Sep 2011
    Posts
    100
    Thanks given
    5
    Thanks received
    5
    Rep Power
    29
    Quote Originally Posted by S Quare Quxx View Post
    1. Depends on your server, usually incoming frames are loaded into an array once
    2. You are using setters wrong, setters are used to set values for private variables inside the class the setter is in. If you want to change a value of the player, you should use something like nickname.getPlayer().setVariable(123);
    Oh fuck lol yeah, Quxx is right with the 2nd point. Meh gtg sleep.
    Reply With Quote  
     

  6. #6  
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Quote Originally Posted by S Quare Quxx View Post
    1. Depends on your server, usually incoming frames are loaded into an array once
    2. You are using setters wrong, setters are used to set values for private variables inside the class the setter is in. If you want to change a value of the player, you should use something like nickname.getPlayer().setVariable(123);
    Ok I get what you're saying. Im using 508 loading 525 & what I ment is it more stable or more efficient ... like... surely the server would be more stable the less classes are initlised? So, instead of having a class for each player to set variables, it'd be best to just use this class with the setters in by all players, static setters, instead of like

    Code:
    getPlayer().getSettersClass().setVar(int);
    ^ class for each player.

    surely

    Code:
    getWorld().getSettersClass().setVarForPlayer(player, int);
    would be more stable as there only 1 class compared to 1 per player?


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Bump, main post updated


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Sep 2011
    Posts
    100
    Thanks given
    5
    Thanks received
    5
    Rep Power
    29
    Quote Originally Posted by Shadowy View Post
    Ok I get what you're saying. Im using 508 loading 525 & what I ment is it more stable or more efficient ... like... surely the server would be more stable the less classes are initlised? So, instead of having a class for each player to set variables, it'd be best to just use this class with the setters in by all players, static setters, instead of like

    Code:
    getPlayer().getSettersClass().setVar(int);
    ^ class for each player.

    surely

    Code:
    getWorld().getSettersClass().setVarForPlayer(player, int);
    would be more stable as there only 1 class compared to 1 per player?
    Setters are used when the field cannot be accessed outside the class. So if your going to use:

    Code:
    getWorld().getSettersClass().setVarForPlayer(player, int);
    It clearly means you can access the field outside of the class so why font you just set the field's value directly:

    Code:
    player.var = 9000;
    No setter class is obv better then??

    kk going to sleep now.
    Reply With Quote  
     

  9. #9  
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Quote Originally Posted by Legacy166 View Post
    Setters are used when the field cannot be accessed outside the class. So if your going to use:

    Code:
    getWorld().getSettersClass().setVarForPlayer(player, int);
    It clearly means you can access the field outside of the class so why font you just set the field's value directly:

    Code:
    player.var = 9000;
    No setter class is obv better then??

    kk going to sleep now.
    Yeah, z508 uses both (I understand what you're saying). Thankyou very much, nightnight

    OT: question not answered lol.


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #10  
    Author of the first public OSRSPS

    Shadowy's Avatar
    Join Date
    Sep 2009
    Age
    23
    Posts
    1,498
    Thanks given
    461
    Thanks received
    237
    Discord
    summit#6514
    Rep Power
    244
    Updated main post


    [Only registered and activated users can see links. ] [Closed]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [Request] EXP gaining info.
    By Shadowy in forum Chat
    Replies: 1
    Last Post: 12-23-2011, 03:13 AM
  2. Replies: 0
    Last Post: 12-19-2011, 07:16 PM
  3. [Java api Info #1]
    By Sir Tom in forum Application Development
    Replies: 1
    Last Post: 06-02-2010, 11:25 PM
  4. Spirit shield info for item.java
    By jordan641 in forum Configuration
    Replies: 5
    Last Post: 04-21-2010, 07:59 PM
  5. Java display System Info?
    By Alex in forum Help
    Replies: 1
    Last Post: 04-09-2010, 01:58 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •