Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Questions about variables and using them

    Lately I've been doing some modding for a game called Minecraft which requires some programming in Java. I've been doing a lot of research but because I can't think of a simplified version of my questions it's hard to get any results from Google. So I'm hoping someone could answer these for me. If you can't, I would even appreciate being pointed in the right direction or led to some reading material that would answer these questions for me.

    1) How can I add the value of a variable onto the name of another variable.
    For instance, I have this line of code
    Code:
    EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron));
    and this variable that will always be a number
    Code:
    private int numberA;
    I would like to add the value of numberA onto entityitem. So if numberA was 1 entityitem would become entityitem1.

    2) What is the best variable type to store values such as Item.coal, which is an object within the game? Would a String type suffice?

    3) Using the same code above:
    Code:
    EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron));
    How could I use a variable's value where Item.ingotIron is? I tried some different things but the compiler threw "ItemStack doesn't exist" or some error along those lines at me.

    For instance if variableA's value is Item.coal, how could I use that variables value where Item.ingotIron is.
    Code:
    EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(variableA));

    I appreciate your time and help on this issue and anything you can provide will be greatly appreciated.
    Last edited by DanielBoone; 10-04-2011 at 03:43 AM.

  • #2
    New Coder
    Join Date
    Mar 2010
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post
    This is a forum for JavaScript not Java, it is a common mistake.

    As for your trouble...

    For your first problem, it looks like you are trying to learn how to use an array An array in Java must be declared as an array of a certain type. You may also want to read up on the java.util.ArrayList and java.util.HashMap objects as they are very helpful. Googling these terms and reading will help you learn about them.

    Second, the coal will be of type.. well.. coal. You will figure this out as you read more about object oriented programming with Java.

    The third problem seems to be specific to minecraft and I am sorry to say I have no experience with it.

    Have fun with making your mod

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much for your response and I apologize for my mistake. I'll mark this topic as resolved and just do some more research and see what I can dig up. If worse comes to worth I'll have to approach my mod in a different way.


  •  

    Tags for this Thread

    Posting Permissions

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