Results 1 to 5 of 5
  1. #1
    ViciousDead is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Sorry, I'm a newb at Java... Could someone explain something in detail for me...

    Okay, I am trying to write a simple java text based game, I have gotten pretty far into it, but it's starting to get complicated. I just can't seem to understand how to send and how to retrieve variables from other Classes... For instance here is one of the many things I have tried...

    Inside my Character.java(I have other stuff in this file, but it's a bit long, and my only problem occurs in this method.):
    Java Code:
      public void battleStart(int dmg){
        int bHp =+ maxHealth;
        int bMp =+ maxMana;
        int bStr =+ statStr;
        int bInt =+ statInt;
        int bDef =+ statDef;
        int bDex =+ statDex;
        Mage pClass = new Mage();
        System.out.(pClass.nAtk(0, bStr));
        System.out.Println(dmg);
      }
    Inside my Mage.java:
    Java Code:
    import static java.lang.System.*;
    import java.util.Scanner;
    
    public class Mage{
      Scanner getText = new Scanner(System.in);
      Character player = new Character();
      
      public void nAtk(int dmg, int bStr){
        dmg = (bStr/2);
        System.out.print(player.battleStart(dmg));
      }
    }
    But I get Void errors, and same with using Static... I don't really understand how this works... :(sweat):

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Sorry, I'm a newb at Java... Could someone explain something in detail for me...

    I'll try my best.

    In this method call:

    Java Code:
    System.out.print(player.battleStart(dmg));
    This part player.battleStart(dmg) calls player's battleStart method passing in an int. So far so good.

    The System.out.print part takes whatever was returned from the battleStart(...) method and tries to print it to the console. But we have to ask, what exactly is returned from the battleStart(...) method? Well if we look at the method code we see it returns void, meaning it in fact returns nothing, and this won't fly.

    I suggest that you get all System.out.println(...) and System.out.print(...) method calls from non user-interface classes and only have these methods in the UI classes. Re-write battleStart and other methods to return something if needed. For instance, this method will need to return a String.

    And keep reading and studying the tutorials as you will find this information all there, and likely much better explained than my poor attempt.

    Good luck.

  3. #3
    ViciousDead is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Sorry, I'm a newb at Java... Could someone explain something in detail for me...

    Okay, if you can find any tutorials for this could you please post them. Thanks for the help, I'll try my best to figure this out.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  5. #5
    ViciousDead is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Sorry, I'm a newb at Java... Could someone explain something in detail for me...

    WOW, that's a lot of information.... Thank you, I'll start reading right away. xD

Similar Threads

  1. Replies: 2
    Last Post: 12-13-2010, 01:34 PM
  2. Replies: 3
    Last Post: 12-13-2010, 07:22 AM
  3. Master Detail Form In Java
    By anilmohan in forum Advanced Java
    Replies: 0
    Last Post: 11-19-2010, 10:04 AM
  4. overiew and detail in java
    By kumar_gemi in forum AWT / Swing
    Replies: 5
    Last Post: 08-20-2009, 01:15 PM
  5. Java newb Q: 8-digit id
    By 1111FM in forum New To Java
    Replies: 2
    Last Post: 09-29-2008, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •