General Discussion Forum

Topic: Java can go...

Showing 21 to 35 of 35

AuthorMessage
Avatar

ATRUEZELDAFAN

21. Posted:

I like cookies with my java.... does that fit in with whats going on here?

CHECK OUT MY AWSOME VIDS! http://www.youtube.com/user/ATRUEZELDAFAN

AuthorMessage
Avatar

Vendetta

22. Posted:

C'mon, motherf***er! It can't be that hard, it's just lift versus drag and rotation!

(If you're not laughing, you haven't seen the movie.)

Edited on by Vendetta

Ex cineribus resurgo
Wii / Speak / Music: 3991 9961 5576 0184 · · · · Mario Kart Wii: 3609 8999 1445· · · · · · · ·Alien Crush: 1934 4006 9660
The Conduit: 2622 0458 3119· · · · · · · · · · · · · · Water Warfare: 4726 5832 1608· · · · · · · Onslaught: 0388 6842 8268

AuthorMessage
Avatar

grenworthshero

23. Posted:

Java does suck. I only got a little into Javascript and that's as far as my coding knowledge went before I gave up, and that was 6 years ago.

PSN ID: grenworthshero
Steam: grenworthshero
WiiU: grenworthshero
3DS Code: 3823-8687-7682
***
YouTube--backloggery--tumblr--Facebook--last.fm

Nintendo Network ID: grenworthshero

AuthorMessage
Avatar

skywake

24. Posted:

Java != Javascript .... the two are entirely different

NNID: skywake

AuthorMessage
Avatar

thewiirocks

25. Posted:

pixelman wrote:

For the simple reason that public static arrays that are defined by subclasses of superclasses are changing the values of all of the arrays for all of the other subclasses of the superclass each time I define the array for a subclass, hence I can't have different values for the static arrays in subclasses of superclasses for some retarded reason.

So you haven't yet learned how to do inheritance correctly, and therefore the language is bad? Ooookkaaayy....

grenworthshero wrote:

Java does suck. I only got a little into Javascript and that's as far as my coding knowledge went before I gave up, and that was 6 years ago.

Repeat after me:

Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript
Java is not the same as Javascript

You might want to write that on the blackboard a few hundred times to make sure that no one else gets confused. ;)

thewiirocks

AuthorMessage
Avatar

grenworthshero

26. Posted:

I know it's not the same. I'm just saying, I only got so far as learning Javascript. I don't think anyone here actually thinks the two are the same thing, anyway.

Edited on by grenworthshero

PSN ID: grenworthshero
Steam: grenworthshero
WiiU: grenworthshero
3DS Code: 3823-8687-7682
***
YouTube--backloggery--tumblr--Facebook--last.fm

Nintendo Network ID: grenworthshero

AuthorMessage
Avatar

skywake

27. Posted:

They aren't just not the same. They are entirely different.... my dislike for Java is more to do with the fact that its so verbose
public static void main(String args[])
{
System.out.println("hello world!");
}

bleh... I know that C has its own issues but I'd take the C equivalent anyday
int main()
{
printf("hello, world");
return 0;
}

Edited on by skywake

NNID: skywake

AuthorMessage
Avatar

pixelman

28. Posted:

@thewiirocks: I do know how to do inheritance correctly. Java just seems to do it differently from other languages I know, and it's not as convenient. I'll try to explain more clearly:

I had an Entity class that had a static array value named "groups". The groups value is supposed to be defined as so:

Entity.groups = new {objects, etc};

So when an entity was created, it'd be added to all of the predefined groups. The problem surfaced when I added subclasses and defined the groups for each class separately. IE,

Player.groups = new {objects};
Platform.groups = new {objects, platforms};

Oddly enough, when I set the Platform's groups it changed the Player's groups as well. I finally concluded that changing a subclass's static value changed the superclass's static value, and thus affected all of its subclasses. I tried predefining "groups" for each class, but the Entity wouldn't recognize the values from its subclasses.

So basically, the method I was trying simply won't work in Java, though it does in Python, which annoys me. But anyway, I switched to a different method using hashtables, and it works now.

I made Kid Tripp! PocketGamer gave it a 9 out of 10! You should totally buy it now!
[16:39] BadKitty: you trying to steal stuff from me? u_u
[16:41] kribs: don't worry Emmy, even if poix tried to steal something from you, he wouldn't finish stealing it

3DS Friend Code: 1123-6536-5321 | Nintendo Network ID: pixelpowa | Twitter: thatpixelguy

AuthorMessage
Avatar

pixelman

29. Posted:

ATRUEZELDAFAN wrote:

I like cookies with my java.... does that fit in with whats going on here?

Yes:

var expire_date = new Date();
var expire_days = 5;
expire_date.setDate(expire_date.getDate()+expire_days);
document.cookie = "Chocolate Chip" + "=" + escape("2") + ((expire_days==null) ? "" : ";expires="+expire_date.toGMTString());

I made Kid Tripp! PocketGamer gave it a 9 out of 10! You should totally buy it now!
[16:39] BadKitty: you trying to steal stuff from me? u_u
[16:41] kribs: don't worry Emmy, even if poix tried to steal something from you, he wouldn't finish stealing it

3DS Friend Code: 1123-6536-5321 | Nintendo Network ID: pixelpowa | Twitter: thatpixelguy

AuthorMessage
Avatar

thewiirocks

30. Posted:

I'm going to take a wild guess and say you tried to do something like this:

public class Entity { public static Object[] groups; }
public class Player extends Entity { }
public class Platform extends Entity { }

Then when you tried to set Player.groups, you found that it was exactly the same as Platform.groups. Because you were expecting an aggregate class definition for Player and Platform. Of course, it doesn't work because Java uses virtual inheritance. An instance of Entity is created as the superclass each time you instantiate Player and Platform.

The correct solution is to override the static value. Here's a test case:

Entity wrote:

public class Entity
{
public static Object[] groups;

public static void main(String[] args)
{
groups = new Object[]{"Test 3"};

Player.groups = new Object[]{"Test 1"};
Platform.groups = new Object[]{"Test 2"};

System.out.println(groups[0]);
System.out.println(Player.groups[0]);
System.out.println(Platform.groups[0]);

Player player = new Player();
Platform platform = new Platform();
}
}

player wrote:

public class Player extends Entity
{
public static Object[] groups;

public Player()
{
System.out.println("From Player: "+groups[0]);
}
}

Platform wrote:

public class Platform extends Entity
{
public static Object[] groups;

public Platform()
{
System.out.println("From Platform: "+groups[0]);
}
}

The output is what you are looking for:

Output wrote:

Test 3
Test 1
Test 2
From Player: Test 1
From Platform: Test 2

As I said, you don't understand inheritance. Different languages provide different features and designs to manage objects differently. Some things are easy in Python but hard in Java. Some things are easy in Java but hard in Python. Don't even get me started on what happens if you try a classless language like Javascript.

Learn the language your using. Don't just get P.O.ed because it doesn't work like some other language you know. All you'll get for that is a nice fire lit under your ass for not seeking assistance.

thewiirocks

AuthorMessage
Avatar

pixelman

31. Posted:

@thewiirocks: Yes, you're correct, I was doing that.

And actually, I did try overwriting "public static Object[] groups;" in each subclass, but the Entity superclass apparently wouldn't recognize the values (though the subclasses did). The Entity is what needs to know what the groups are, not its subclasses, because I was doing something like this:

Entity wrote:

public class Entity {
public static Group[] groups;
Entity() {
for(int i=0; i<groups.length; i++) {
groups[i].add(this);
}
}
}

Though you seem to think it works and you obviously have more experience than me, so I guess I was just doing something stupid. :P

I made Kid Tripp! PocketGamer gave it a 9 out of 10! You should totally buy it now!
[16:39] BadKitty: you trying to steal stuff from me? u_u
[16:41] kribs: don't worry Emmy, even if poix tried to steal something from you, he wouldn't finish stealing it

3DS Friend Code: 1123-6536-5321 | Nintendo Network ID: pixelpowa | Twitter: thatpixelguy

AuthorMessage
Avatar

thewiirocks

32. Posted:

You've got the right idea, but the problem is that you'll have to move that add() code to the descendant class. Entity can't see the static values of the children. Again, you have to remember that Java creates a separate instance of Platform and Entity. The JVM will go from the top to the bottom when looking for something (e.g. Platform -> Entity) but it won't go the other way around unless a contract is created. Unfortunately, you can't create a contract with static values.

The solution is to do something like this:

public class Entity
{
protected Entity(Group[] defaultGroups)
{
for(int i=0; i<groups.length; i++) groups[i].add(this);
}
}

public class Player extends Entity
{
public static Group[] groups;

public Player()
{
super(groups);
}
}

That will initialize the class with the groups you want. As long as you do NOT specify a default constructor for Entity, any class extending Entity will be forced to pass in their default groups.

Does that resolve your issue? :)

Edited on by thewiirocks

thewiirocks

AuthorMessage
Avatar

pixelman

33. Posted:

Aha. Yes, that'll work. I like that much better than the method I'm currently using, so I'll port the code over later on today. Thanks for the help! :)

Edited on by pixelman

I made Kid Tripp! PocketGamer gave it a 9 out of 10! You should totally buy it now!
[16:39] BadKitty: you trying to steal stuff from me? u_u
[16:41] kribs: don't worry Emmy, even if poix tried to steal something from you, he wouldn't finish stealing it

3DS Friend Code: 1123-6536-5321 | Nintendo Network ID: pixelpowa | Twitter: thatpixelguy

AuthorMessage
Avatar

thewiirocks

34. Posted:

Happy to be of assistance. :)

thewiirocks

AuthorMessage
Avatar

pixelman

35. Posted:

I'm back in my "I hate Java" mood. Everything was going as smooth as silk until I ran into sound playback. So I go...

AudioClip jump_sound = java.applet.Applet.newAudioClip(Game.class.getResource("/sounds/jump.wav"));

It loads fine. I play it once (jump_sound.play()), it plays fine. I play it again, and there's a 1-2 second delay before it plays. I've searched forums, google, all over for people with related problems, but I can't find anything.

@thewiirocks: Do you have any EXP with java sound? If so, do you have any suggestions?

Edit: Guhh. After hours of researching and testing, I finally concluded that it's a linux-specific bug. Argh! Linux sound sucks.

Edited on by pixelman

I made Kid Tripp! PocketGamer gave it a 9 out of 10! You should totally buy it now!
[16:39] BadKitty: you trying to steal stuff from me? u_u
[16:41] kribs: don't worry Emmy, even if poix tried to steal something from you, he wouldn't finish stealing it

3DS Friend Code: 1123-6536-5321 | Nintendo Network ID: pixelpowa | Twitter: thatpixelguy