View Full Version : Resolved Questions about variables and using them

10-04-2011, 03:48 AM
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

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

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:

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.

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.

10-04-2011, 04:36 AM
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 :)

10-04-2011, 04:43 AM
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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum