Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2011, 02:48 AM   PM User | #1
DanielBoone
New to the CF scene

 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
DanielBoone is an unknown quantity at this point
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..
DanielBoone is offline   Reply With Quote
Old 10-04-2011, 03:36 AM   PM User | #2
coiner
New Coder

 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 1 Time in 1 Post
coiner is an unknown quantity at this point
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
coiner is offline   Reply With Quote
Old 10-04-2011, 03:43 AM   PM User | #3
DanielBoone
New to the CF scene

 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
DanielBoone is an unknown quantity at this point
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.
DanielBoone is offline   Reply With Quote
Reply

Bookmarks

Tags
variable, variables

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:39 AM.


Advertisement
Log in to turn off these ads.