Results 1 to 7 of 7
Thread: Choose between to id's (or)
- 04-11-2012, 07:45 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Choose between to id's (or)
Hello I have this line of code
1856 = item idJava Code:player.getInventory().addItem(1856, 1);
1 = amount
I would like it to choose between two objects at random. So lets say I have it set up like (1856, 1) (1870, 1) and then it will choose one of those at random.
I have tried setting it up multiple ways and can't figure it out..
Thanks for any help!
- 04-11-2012, 08:00 AM #2
- 04-11-2012, 08:17 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Re: Choose between to id's (or)
Yes i'm checking it out right now. I have set up a class file that looks like this
Does this look correct?Java Code:public class PkDrops { public static int PkDrops[] = {3101,4151,11694,11696,11698,11700}; public static int PkDrops() { return PkDrops[(int)(Math.random()*PkDrops.length)]; } }
- 04-11-2012, 09:16 AM #4
Re: Choose between to id's (or)
Use the more modern java.util.Random instead. Shortens your code and makes it more readable.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-11-2012, 07:09 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Re: Choose between to id's (or)
How would I do that sorry i'm fairly new to Java.
Also I'm confused on how to get this to print the selection.
Java Code:package src; public class PkDrops { public static int PkDrop[] = {3101,4151,11694,11696,11698,11700}; public static int PkDrop() { return PkDrop[(int)(Math.random()*PkDrop.length)]; } public static void main(String[] args){ System.out.println("PkDrop"); } }Last edited by Sean2012; 04-11-2012 at 07:29 PM.
- 04-11-2012, 07:51 PM #6
Re: Choose between to id's (or)
Do you know where to find the API?
db
edit Go through http://www.oracle.com/technetwork/ja...oc-136057.html . Variable and method names should start with a lowercase letter.
And it's poor design to have a variable and a method with the same name. You're only going to confuse yourself and anyone who reads your code with that.Why do they call it rush hour when nothing moves? - Robin Williams
- 04-14-2012, 07:21 PM #7
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
12 reasons why I choose to be in IT industry
By DK Bello in forum EntertainmentReplies: 1Last Post: 01-06-2012, 08:53 AM -
help to choose
By NoWayOut in forum New To JavaReplies: 3Last Post: 06-05-2011, 03:54 PM -
how to choose the field where last JTextField
By aledara in forum Advanced JavaReplies: 8Last Post: 12-07-2010, 10:16 PM -
what to choose???(awt or swing)
By moshe12007 in forum AWT / SwingReplies: 11Last Post: 08-14-2009, 11:10 AM -
Why to Use Eclipse IDE and Option for this IDE to choose with other's IDE?
By mgrprasad90 in forum EclipseReplies: 0Last Post: 08-27-2008, 09:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks