Calling an int to another class

Discussion in 'Plugin Development' started by pc_h8r, Feb 2, 2013.

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

    pc_h8r

    Hello. I am modifying a plugin for my personal use.

    I have an int called Bluescore and Redscore

    if a player on the red team kills someone, a point gets added to the red team, and the int Redscore goes up one.

    in the other class, I need to compare the Blusecore int and the Redscore int to see which team wins. how can i get those two ints from the first class to the second class??
     
  2. Offline

    ZeusAllMighty11

    Code:
    public int score = 0; // makes 'score' accesible
    
    Code:
    private ClassThatHasScore variable;
    
    then to get:

    Code:
    variable.score // etc
    
     
  3. Offline

    pc_h8r

    so would it be:

    Code:
    Class1
     
    blablabla
     
    public int Bluescore = 0;
    
    Code:
    Class2
     
    Blablabla
     
    private Class1 Bluescore
    variable.Bluescore
    
    then i can use that variable in class2?

    Is this correct??

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

    ZeusAllMighty11

    No.


    I suggest learning what a constructor is
     
  5. Offline

    pc_h8r

    ok, I will do that. In the meantime, could you explain what the code you posted above does?

    I understand the first part, but not the second or third.

    Well, I couldn't figure out constructors.

    Is there a VERY descriptive guide that you may know of?



    (The main class writes the int value and the other 2 classes read the value)

    What about this?

    Code:
    class1
     
    public int score = 7;
    private class1 variable;
    Code:
    class2
     
    int placeholder;
     
    variable.score = placeholder;
    then I can use the int of placeholder in class 2 and it will be the same as the int score from class1?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    ZeusAllMighty11

    You need to reference a class to use it's methods

    Code:
    public class HelloWorld {
        public int test = 5;
    }
    
    Code:
    public class MathWorld {
        private HelloWorld helloworld = new HelloWorld();
        
        System.out.println(helloworld.test + "" );
    }
    
     
  7. Offline

    microgeek

    Please learn proper Java, then come back.
    :rolleyes:
     
  8. Offline

    pc_h8r

    Ok, I was just trying to see what I knew so far.
     
Thread Status:
Not open for further replies.

Share This Page