brad9873
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 3208 |
|
|
| 08 May 2012 08:48 PM |
| I know this place is for Roblox scripters, but I have a problem with some java code and decide I could possibly ask you guys if you know any java? |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
| |
|
|
| 08 May 2012 08:51 PM |
| I'm still learning it, but know a decent amount |
|
|
| Report Abuse |
|
|
brad9873
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 3208 |
|
|
| 08 May 2012 08:53 PM |
Well I was creating an object for an enemy when I encountered a problem. I will give you the object I created but not the main class unless you need it. I just made the objects first and I haven't messed with the actual methods and the main method. Here is the zombie object:
class Zombie { enemy zombie = new enemy(); health = 10; String name = "Zombie"; chance = (Math.random() * 10); void fight(){ } }
I was trying to force the math.random into an int. I haven't started the fight method yet. The problem is that on the "enemy zombie = new enemy();" it says I need a , instead of ;. Also on the chance it says I need an extra ) to complete the block.
Note; I am using eclipse to help me. I have not really worked on the rest of the code. The enemy is the main class. Very basic I know. |
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:18 PM |
| I need ALL classes you're using in order to fix it. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 08 May 2012 09:19 PM |
| Can you give us the EXACT output please? |
|
|
| Report Abuse |
|
|
brad9873
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 3208 |
|
|
| 08 May 2012 09:25 PM |
All the classes(2, Just started the script. Very basic.) Enemy Class:
class enemy { int health; String name; int chance; void fight(){ } }
Zombie Class:
class Zombie { enemy zombie = new enemy(); health = 10; String name = "Zombie"; chance = (Math.random() * 10); void fight(){ } }
|
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:26 PM |
| Just extend enemy instead perhaps? |
|
|
| Report Abuse |
|
|
brad9873
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 3208 |
|
|
| 08 May 2012 09:27 PM |
@Crazy I could do that but I have been practicing with objects lately and I decided this would be a nice way to. I wanted to try it out and this is the problem I encountered. |
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:32 PM |
Yes, do what CM says.
class enemy { int health; String name; int chance;
void fight(){ // no modifiers? i suggest just making it public }
public enemy(int health, String name, int chance) { this.health = health; this.name = name; this.chance = chance; } }
class Zombie extends enemy {
void fight(){ // again i suggest the use of public here }
public Zombie() { super(10, "Zombie", (int)(Math.random()*10)); } }
class Test { public static void main(String[] args) { Zombie monst = new Zombie(); } } |
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:34 PM |
| Wewt I actually knew something about Java for once! I'm learning ;') |
|
|
| Report Abuse |
|
|
brad9873
|
  |
| Joined: 26 Jul 2009 |
| Total Posts: 3208 |
|
|
| 08 May 2012 09:34 PM |
| I was going to fill in the methods after this. I plan to have multiple objects so that is why I was wondering why this wouldn't work. |
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:34 PM |
| Is it possible to use Java with Roblox or is this just some playing around with a zombie class in Java? |
|
|
| Report Abuse |
|
|
|
| 08 May 2012 09:36 PM |
Roblox does not use Java.
What do you mean by "using objects" ?? When you "extend" an object (known as inheritance), you're creating an object anyway. Heck, everything in Java is an object. Even those darned error messages. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 08 May 2012 11:27 PM |
| My OOP stuff on roblox has extends in it if you need to take a look fortunato. Also you would only be able to use java on roblox if you made your own custom compiler, which would be a pain and if you were to do something like that on roblox you should really make it your own custom markup or scripting language so that it has more functionality here. |
|
|
| Report Abuse |
|
|