Current Events > ProgrammingGeneral++

Topic List
Page List: 1, 2
ChocoboMog123
12/28/21 4:51:40 PM
#1:


@SpiritSephiroth
@SomeLikeItHoth
@1337toothbrush
@Questionmarktarius

I was working on a game in Java but took a couple of months off to work on a Unix scripting class.
Now going back to my game, I fixed up a few things before running into some roadblocks. It's a basic RPG-style game, but I need some way to determine turn order. I have the MC as a Character->PlayerCharacter object and some enemies in an array of Character->EnemyClass->(EnemyType) objects. Each actor will have a random "turn timer" variable based on their speed to determine order. I tried to make an array holding all of these actors together so I can reorder them as needed, but I'm running into:
Exception in thread "main" java.lang.ArrayStoreException: com.company.PlayerCharacter
I think it's because of a mismatch of object types from these lines:
Character[] actors = Arrays.copyOf(enemy, enemy.length + 1); //create an array of all actors
actors[actors.length-1] = mainCharacter;
Basically trying to expand an array to fit in the MC, but I think the Arrays.copyOf() is creating issues. I'm good with lists and hash maps in python, but not so much in Java. Any clues? Maybe there's just a better way to create a turn order...

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
SomeLikeItHoth
12/28/21 5:09:00 PM
#2:


I've never worked with java before. I spent a few weeks on a fun little text based RPG using Python over the summer but I ran into some issues so I took a break to learn more. Right now I'm focusing on web dev so I can get my career started faster. What I did in my RPG was I gave each character a random speed stat, depending on which class they were. Knights had a speed stat between 1 - 5, thieves 2 - 10, etc. Then each turn, a random number was chosen for each class, and whoever had the highest number would strike first. It was very basic, but I was trying to teach myself OOP and this seemed like the best way.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
Questionmarktarius
12/28/21 5:11:25 PM
#3:


My java is super rusty, but you may be better off just doing an array push for the mainCharacter.
Or, just a have a turn order array that references the enemy/PC objects.
... Copied to Clipboard!
SpiritSephiroth
12/28/21 5:25:21 PM
#4:


Oh hey, thanks for making this topic. Been too busy to make a new one but I'll update my progress here time to time.

---
https://i.imgur.com/spfW7gv.jpg https://i.imgur.com/EAuZ5LW.jpg https://i.imgur.com/ZzXmr8X.jpg
... Copied to Clipboard!
ChocoboMog123
12/28/21 5:51:34 PM
#5:


Questionmarktarius posted...


Or, just a have a turn order array that references the enemy/PC objects.
That's a good idea. Make an array of the needed size, reference each actor by some unique ID and fill it appropriately. The problem, ultimately, is just iterating through x elements of somewhat different types and it will probably come back when I get to damage and actions.

Eventually I'll upload all my scripts from my Unix class to github and post them here. If anyone is interested in learning awk, perl, or some bash scripts for parsing text I can share the vids. The instructor actually had a ton of really niche gaming references in the material.

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
SomeLikeItHoth
12/28/21 5:55:20 PM
#6:


Have y'all read any good programming books lately? I'm looking to find some new reads for the new year.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
Questionmarktarius
12/28/21 5:59:41 PM
#7:


ChocoboMog123 posted...
The problem, ultimately, is just iterating through x elements of somewhat different types and it will probably come back when I get to damage and actions.
If they have the same superclass, it'll work.
... Copied to Clipboard!
1337toothbrush
12/28/21 8:53:43 PM
#8:


ChocoboMog123 posted...
That's a good idea. Make an array of the needed size, reference each actor by some unique ID and fill it appropriately. The problem, ultimately, is just iterating through x elements of somewhat different types and it will probably come back when I get to damage and actions.

Eventually I'll upload all my scripts from my Unix class to github and post them here. If anyone is interested in learning awk, perl, or some bash scripts for parsing text I can share the vids. The instructor actually had a ton of really niche gaming references in the material.

Yeah, the problem is that when you assign the Character array to an array of a different type, the limitations of that array apply to it. So you assigned an array of EnemyClass to actors, thus it will act like one (and so can't hold PlayerCharacter), you should do this instead:

Character[] actors = new Character[enemy.length + 1];
for (int i = 0; i < enemy.length; ++i) actors[i] = enemy[i];
actors[actors.length-1] = mainCharacter;

Now if you want to put them all in the same array, you'll need a common method (e.g. Character has a method turn() which handles how the character carries out their turn). If it makes sense, you could always keep enemies and player characters separate and then simply iterate the two arrays based on speed. For example:

Arrays.sort(enemy, (Character a, Character b) -> a.getTurnOrder() - b.getTurnOrder());
Arrays.sort(player, (Character a, Character b) -> a.getTurnOrder() - b.getTurnOrder());
int enemyIndex = 0, playerIndex = 0;
while (enemyIndex < enemy.length || playerIndex < player.length) {
boolean playerTurn;
if (enemyIndex == enemy.length) playerTurn = true;
else if (playerIndex == player.length) playerTurn = false;
else if (player[playerIndex].getTurnOrder() <= enemy[enemyIndex].getTurnOrder()) playerTurn = true;
else playerTurn = false;

if (playerTurn) player[playerIndex++].turn();
else enemy[enemyIndex++].turn();
}

You sort both arrays by turn order and then advance the index based on which one is faster (or just advance the other array if one has been iterated through entirely already).

---
https://imgur.com/a/FU9H8 - http://imgur.com/ZkQRDsR.png - http://imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
ChocoboMog123
12/28/21 10:25:43 PM
#9:


1337toothbrush posted...


Character[] actors = new Character[enemy.length + 1];
for (int i = 0; i < enemy.length; ++i) actors[i] = enemy[i];
actors[actors.length-1] = mainCharacter;

Now if you want to put them all in the same array, you'll need a common method (e.g. Character has a method turn() which handles how the character carries out their turn). If it makes sense, you could always keep enemies and player characters separate and then simply iterate the two arrays based on speed. For example:
Yoooooo. That worked! Thanks for the detailed explanation, I knew it was something like that. I was planning on just converting everything to one major class and making a mess of the rest of it, but this works great.
I have an upper interface of Character that gets implemented by everything else, so common characteristics like speed and turnTime() are easy. Each object tracks its own health, damage, death status, etc. Still working on actually putting it all together, but the foundation is there.

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
#10
Post #10 was unavailable or deleted.
CreekCo
12/28/21 10:54:25 PM
#11:


Cool thread

---
All we have to do, is take these lies and make them true somehow
All we have to see, is that I don't belong to you and you don't belong to me -- Freedom '90 GM.
... Copied to Clipboard!
Rexdragon125
12/29/21 4:46:20 PM
#12:


I've been coding C# for around 10 years for my work, I'm pretty rusty on my Java though they're pretty similar.

If you're just learning to code, stick to making text output or command line program until you're comfortable with the language. I see a lot of new programmers try to start on a game engine like Unity, or a windowed GUI system. You're going to have a bad time trying to learn both the language and the GUI's interface at the same time. Learn the language first.
... Copied to Clipboard!
Questionmarktarius
12/29/21 4:50:22 PM
#13:


Rexdragon125 posted...
You're going to have a bad time trying to learn both the language and the GUI's interface at the same time. Learn the language first.
This.

Make it work, then make it pretty.
... Copied to Clipboard!
#14
Post #14 was unavailable or deleted.
Medussa
12/29/21 4:52:53 PM
#15:


[LFAQs-redacted-quote]



---
Boom! That's right, this is all happening! You cannot change the channel now!
Brought to you by... The Space Pope
... Copied to Clipboard!
s0nicfan
12/29/21 4:53:45 PM
#16:


FYI if you're going to keep the characters in an array you might as well use a priority queue that's part of the language anyway. That way you don't run into weird array index issues and the array itself will always keep track of turn order. You'll just need to write a small comparator function that uses the Character's "turn timer" member variable as the basis of comparison.

https://www.geeksforgeeks.org/priority-queue-class-in-java/


---
"History Is Much Like An Endless Waltz. The Three Beats Of War, Peace And Revolution Continue On Forever." - Gundam Wing: Endless Waltz
... Copied to Clipboard!
Questionmarktarius
12/29/21 5:05:32 PM
#17:


[LFAQs-redacted-quote]

Nobody really bothers with that anymore.
... Copied to Clipboard!
s0nicfan
12/29/21 5:12:41 PM
#18:


Rexdragon125 posted...
You're going to have a bad time trying to learn both the language and the GUI's interface at the same time. Learn the language first.

I sort of disagree.The most important thing at these early stages for a hobbyist is learning the language-agnostic concepts and doing so in a way that feels rewarding. In a classroom setting spending multiple semesters on command line programs is an excellent way to learn, but most people would quit out of boredom well before they got good enough on their own. I agree that large tools like Unity/Unreal are too much, but simple UI development or scripting inside tools is a great way to learn the basics and feel good about what you create.

I'm sure a lot of people cut their teeth on programming doing things like modding (Neverwinter Nights being one of the best examples). That's why most of the best tools for teaching programming to children now and visual languages like Scratch.

---
"History Is Much Like An Endless Waltz. The Three Beats Of War, Peace And Revolution Continue On Forever." - Gundam Wing: Endless Waltz
... Copied to Clipboard!
#19
Post #19 was unavailable or deleted.
Questionmarktarius
12/29/21 5:18:47 PM
#20:


[LFAQs-redacted-quote]

"our site runs terribly, please fix it"
[wordpress site with a bloated and badly mis-configured "universal" theme, and literally a hundred plugins, most of which are fighting to do the same simple thing a few lines of php could have done.]
... Copied to Clipboard!
1337toothbrush
12/29/21 11:01:48 PM
#21:


s0nicfan posted...
FYI if you're going to keep the characters in an array you might as well use a priority queue that's part of the language anyway. That way you don't run into weird array index issues and the array itself will always keep track of turn order. You'll just need to write a small comparator function that uses the Character's "turn timer" member variable as the basis of comparison.

https://www.geeksforgeeks.org/priority-queue-class-in-java/
A priority queue is overkill for the typical number of characters in an RPG battle. Simply put them in a regular array and sort.

---
https://imgur.com/a/FU9H8 - https://imgur.com/ZkQRDsR.png - https://imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
SomeLikeItHoth
12/30/21 6:01:40 AM
#22:


I ordered some new books! Theyll be here in like 14 hours.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
Kloe_Rinz
12/30/21 6:07:39 AM
#23:


i got mediocre grades in uni (except for web dev), and since then ive mainly been using powershell. i want to "get good" at programming at some point, but i feel like anytime i want to do anything I've got to google "how to do X in language", or have an man page or documentation up at nearly all times doing even basic shit

how do yall get so good and write actually good code and solve non-trivial problems
most complex thing I ever did was my uni assignment where i basically developed a small e-commerce site. front end, back end and database. but my design was shit, and even though the site worked im sure the back end was shit
i dont even know anything about all these frameworks. i just worked directly with html, css, javascript, php and mysql.

i feel like it might be good to learn .net, since that might help a bit with powershell (use daily for my job but mostly one-liners or small scripts), and also transfer across to c# and ASP.NET or something...
... Copied to Clipboard!
darkmaian23
12/30/21 6:21:17 AM
#24:


If you aren't too far along, I'd like to suggest that Java is the wrong choice for basically any game project in 2021. If the game is 2D, go with Godot or Unity, or even RPGMaker if your game is that exact kind of style and you don't mind the stigma. If the game is 3D, go with either Unity or Unreal (the reputation for the difficulty of learning BPs is overblown, and there are some great courses on Udemy that walk you through making simple games from scratch to learn).

If the goal of your game is to get good at a programming language rather than just making a game, there are strong game libraries for JS (and by extension, TS), Python, and even Ruby. The state of game making in pure Java is kind of gross, so if you like the idea of making a game, I'd bite the bullet and learn a language you don't know and make a game with that and broaden your horizons. Pick something else for Java, unless you want to try and write a game in it to get more comfortable with Android app development.

If I've convinced you to try something other than Java, start with some much smaller games that you can complete quickly to build skill and confidence. If you are itching to keep going with your RPG, I'd work on the script, characters, art, music, and all that while you power up.
... Copied to Clipboard!
ChocoboMog123
12/30/21 2:25:47 PM
#25:


I found an "older" better revision of my code I saved on GitHub, so now I have to restructure a few things. But I'm way too burnt out from work yesterday :(

darkmaian23 posted...
If you aren't too far along, I'd like to suggest that Java is the wrong choice for basically any game project in 2021. If the game is 2D, go with Godot or Unity, or even RPGMaker if your game is that exact kind of style and you don't mind the stigma. If the game is 3D, go with either Unity or Unreal (the reputation for the difficulty of learning BPs is overblown, and there are some great courses on Udemy that walk you through making simple games from scratch to learn).

If the goal of your game is to get good at a programming language rather than just making a game, there are strong game libraries for JS (and by extension, TS), Python, and even Ruby. The state of game making in pure Java is kind of gross, so if you like the idea of making a game, I'd bite the bullet and learn a language you don't know and make a game with that and broaden your horizons. Pick something else for Java, unless you want to try and write a game in it to get more comfortable with Android app development.

If I've convinced you to try something other than Java, start with some much smaller games that you can complete quickly to build skill and confidence. If you are itching to keep going with your RPG, I'd work on the script, characters, art, music, and all that while you power up.
I've worked in RPGMaker and think it sucks >_>
This is mostly just a self challenge to build a resume while inbetween classes and work. I started in Java because I had just taken a Java 102 course, but in retrospect I really should have started in Python. But I don't think it'll make enough of a difference in the final project to switch. I definitely wouldn't be comfortable with Unity, but might for my next project.

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
Medussa
12/30/21 2:31:29 PM
#26:


while the subject is up, does anyone have any good unity resources? i've watched through a few "intro to unity" tutorials, but i haven't had much luck finding any guides for the next steps. and my own fumbling though the documentation and various google searchings has been less than ideal.

---
Boom! That's right, this is all happening! You cannot change the channel now!
Brought to you by... The Space Pope
... Copied to Clipboard!
IllegalAlien
12/30/21 2:39:44 PM
#27:


i used java in my last job to implement a Flink stream processing ML system that processed 50m events per 5 minutes and made an anomaly determination for subsets of data

---
"Never argue with an idiot, they drag you down to their level, then beat you with experience."
... Copied to Clipboard!
s0nicfan
12/30/21 2:45:05 PM
#28:


Medussa posted...
while the subject is up, does anyone have any good unity resources? i've watched through a few "intro to unity" tutorials, but i haven't had much luck finding any guides for the next steps. and my own fumbling though the documentation and various google searchings has been less than ideal.

This might be a personal preference but I would recommend downloading one of the tutorial projects off their marketplace and then poking around in one of those rather than trying to start from scratch. For these types of environments I find it easier to start with a basic setup, make changes, and then see what breaks rather than starting from a completely blank workspace. Plus if they have a tutorial for the type of game you were thinking of making you already have some of the grunt work done for you.

https://assetstore.unity.com/essentials/tutorial-projects

---
"History Is Much Like An Endless Waltz. The Three Beats Of War, Peace And Revolution Continue On Forever." - Gundam Wing: Endless Waltz
... Copied to Clipboard!
Rexdragon125
12/30/21 4:20:56 PM
#29:


Yeah, don't bother with Unity tutorials. I tried to learn Unity, and most of the documentation was in the form of several hour Youtube tutorials. Like the official documentation site would link to them. I couldn't just sit through it since they'd all cover some basics and I was already decent at C#. So every time I needed to find a few lines of code for something I'd have to sift through dozens of hours of Youtube tutorials. It doesn't help that Unity has one of the clunkiest APIs I've ever seen and I've been coding for the Windows environment for years. I eventually did succeed in making a decent 2D Sonic inspired physics-based platformer engine but it wasn't worth it. But this was quite a few years ago, they've probably improved.
... Copied to Clipboard!
darkmaian23
12/30/21 10:53:20 PM
#30:


@Medussa
I never had much luck with any free resources. What worked for me were a couple of GameDev.tv courses that I bought on Udemy. There is a sale currently going on so you can snap one or two up for a reasonable amount.
... Copied to Clipboard!
SomeLikeItHoth
12/31/21 4:04:57 AM
#31:


Amazon delivered my books! About to pop open this one and read a bit before bed.

https://www.manning.com/books/secrets-of-the-javascript-ninja

darkmaian23 posted...
that I bought on Udemy.
I'm going through the complete web dev 2022 bootcamp on udemy at the moment. On chapter 36. It's a pretty good course! I've learned a lot over the past month that I've been going through them. As long as you follow along + code along the way you can learn a lot from udemy courses.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
1337toothbrush
12/31/21 4:13:58 AM
#32:


SomeLikeItHoth posted...
Amazon delivered my books! About to pop open this one and read a bit before bed.

https://www.manning.com/books/secrets-of-the-javascript-ninja
The book title says ninja but the cover art looks more like a samurai.

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
Questionmarktarius
12/31/21 4:16:15 AM
#33:


turns out the last couple or three programming books I bought were about Commodore 64 development.

That's come back again, for some reason.
... Copied to Clipboard!
1337toothbrush
12/31/21 4:28:32 AM
#34:


Honestly, I've never read through a book on programming. Even in school we barely touched any textbooks (if any were even assigned). I find learning by following tutorials and then trying out things while referring to documentation to be the best method for me.

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
Questionmarktarius
12/31/21 4:33:41 AM
#35:


https://jeroo.org/
It's a brilliant teaching tool
... Copied to Clipboard!
SomeLikeItHoth
12/31/21 4:42:50 AM
#36:


1337toothbrush posted...
The book title says ninja but the cover art looks more like a samurai.
I guess JavaScript Samurai didn't sound as cool.

Questionmarktarius posted...
turns out the last couple or three programming books I bought were about Commodore 64 development.
Which books were they?

1337toothbrush posted...
Honestly, I've never read through a book on programming.
With book reading it's tough because you need to find one that doesn't have outdated information. Finding stuff online can be better, because anything posted can be updated quickly, whereas books need new versions. But if you can find a good book it's worth reading.

Questionmarktarius posted...
https://jeroo.org/
It's a brilliant teaching tool
I'll have to check that out some time.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
Questionmarktarius
12/31/21 4:46:46 AM
#37:


SomeLikeItHoth posted...
Which books were they?
Retro Game Dev: Commodore 64
Retro Game Dev: Commodore 64 vol 2
A Hobbyist's guide to the C64 Mini
... Copied to Clipboard!
Medussa
12/31/21 9:57:29 AM
#38:


thanks, all. =)

---
Boom! That's right, this is all happening! You cannot change the channel now!
Brought to you by... The Space Pope
... Copied to Clipboard!
ChocoboMog123
12/31/21 4:58:42 PM
#39:


SomeLikeItHoth posted...
I'm going through the complete web dev 2022 bootcamp on udemy at the moment. On chapter 36. It's a pretty good course! I've learned a lot over the past month that I've been going through them. As long as you follow along + code along the way you can learn a lot from udemy courses.
Are any of those Udemy courses actually good? I've tried a few and they always seem to end just when it's getting interesting.

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
#40
Post #40 was unavailable or deleted.
#41
Post #41 was unavailable or deleted.
1337toothbrush
12/31/21 11:54:00 PM
#42:


[LFAQs-redacted-quote]

Question for you and anyone else who uses Java: do you use the newer versions of the language or do you stick with older versions (e.g. 1.8 or 11)?

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
s0nicfan
01/01/22 12:05:46 AM
#43:


1337toothbrush posted...
Question for you and anyone else who uses Java: do you use the newer versions of the language or do you stick with older versions (e.g. 1.8 or 11)?

The latest version of OpenJDK because Oracle monetized the entire language so even if you use an older version you owe them money in a professional setting.

---
"History Is Much Like An Endless Waltz. The Three Beats Of War, Peace And Revolution Continue On Forever." - Gundam Wing: Endless Waltz
... Copied to Clipboard!
1337toothbrush
01/01/22 12:11:16 AM
#44:


Some companies are lazy enough where they'll just pay up.

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
SomeLikeItHoth
01/01/22 5:56:17 AM
#45:


ChocoboMog123 posted...
Are any of those Udemy courses actually good? I've tried a few and they always seem to end just when it's getting interesting.
Yes. There's a lot of trash to sift through, but if you find a good one you can learn a lot. You just have to make sure you code along, or even taking notes / keeping a diary can help. You also need to practice because I've noticed these videos just teach the basics & It's up to you to keep going with them. If you're interested just let me know what you want to learn & I can help you find some good ones.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
Kloe_Rinz
01/01/22 6:14:29 AM
#46:


1337toothbrush posted...
Some companies are lazy enough where they'll just pay up.
i haven't seen any. i deal with some of the shittiest vendors ever and even they opted to go the cheap route than the lazy route. it helps that openjdk is basically a drop-in replacement for traditional java
... Copied to Clipboard!
1337toothbrush
01/01/22 9:37:14 AM
#47:


Kloe_Rinz posted...
i haven't seen any. i deal with some of the shittiest vendors ever and even they opted to go the cheap route than the lazy route. it helps that openjdk is basically a drop-in replacement for traditional java
They're generally larger companies.

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
ChocoboMog123
01/02/22 10:58:38 PM
#48:


Bump

---
"You're sorely underestimating the power of nostalgia goggles." - adjl
http://www.smbc-comics.com/comics/20110218.gif
... Copied to Clipboard!
SomeLikeItHoth
01/03/22 4:59:43 AM
#49:


Been learning / working with mongoDB. Pretty neat stuff. I have little experience with databases so hoping to spend more time learning about them.

---
FAM FOREVER. | https://i.imgur.com/cGrHeeU.jpg
... Copied to Clipboard!
1337toothbrush
01/03/22 6:15:10 AM
#50:


If you want to get experience with databases, I suggest starting with a relational database (e.g. Postgres, MySQL, etc) rather than a NoSQL database like MongoDB.

---
https://imgur.com/a/FU9H8 - https://i.imgur.com/ZkQRDsR.png - https://i.imgur.com/2x2gtgP.jpg
... Copied to Clipboard!
Topic List
Page List: 1, 2