it's actually good practice to have 'case' breakouts for knowns and allow 'default' to catch the unknowns in an error. As for the functions, I tend to program in such a way that if it is only called by one other function, then it doesn't become a subfunction (I put in-line), it's that simple. Yes, sometimes it leads to "huge" functions, but it's far too difficult to track what is going on if you have to jump through 20 sub functions (you can also 'region' out the pieces to collapse them anyway). When I refactor, I may find a way to reduce the code later or find multiple uses of snippets. I also don't usually let my sub functions called other sub functions, I literally want them to do a single task and be done.
im learning to make games and seeing the dev of one of the games i love talking about his mistakes and things like reffering to tutorials is great, make the whole game making thing looks less " otherwordly", thanks for share your experience o/
Utilize others built-in functions before comparing values. When if else and switch are overly used, it will leave you wasting time trying to find the right condition if you needed to come back to it. I'll make my next video about if else and switch as well as how 5:26 can be optimized.
> isn't it like trying to optimize addition or division Divisions are slow. If you’re dividing by a power of two, bit shifts are the way to go. In cases where the divisor is a variable the compiler won’t save you, so divisions are something that absolutely can be optimized.
How do you keep that skill switch statement straight if it's all ints? There's no way you memorized all of those hundreds of skills in the game... right?
I only remember the ones for the update I currently work on. After that, I CTRL+F my profession script as I have all skill names commented along with the id below it lol
@@onebitadventure If i had to venture a guess as to why those were there is if they were to avoid a default case somewhere else in that switch statement. If that's a bad coding practice, I suppose I'm guilty too. lol
@@ScottyRichMusic That switch code was made before I even knew about default lol. No defaults in that switch statement so simply being that code I thought I knew what I was doing, but didn't X)
You think the if else statements in the code is where the sins are committed... Actually you using magic numbers constantly and using strings in switch cases is 100x the crime. Just create variables for the numbers you use in functions and for god's sake use enums. Case "Breakable" and Case 92 isn't the correct way to do it, sure it works but many mistakes will appear while using strings in your code and you won't understand (just like in this video) what case 92 was. But I guess you know all of this now because this game was made 5 years ago. You must have grown as a game developer. I just felt the need to say it. Your game looks quite good, have a nice journey!
i would agree that using enums would be sufficient .. but what i'm more confused about is why he didn't use ScriptableObjects for his Skills .. it would be alot easier to add and remove skills using them.
Thanks for this video. I have a few scripts that I thought were getting a little bloated. I was starting to be concerned about at what point am I going to start seeing some performance issues. After watching this , I'm thinking I'm good to go add a few more things to those scripts with out a bit of fear lol.
Hey, just started learning programming and I don't quite understand why if statements are bad. How would you do it without if statements? Is there another option? I know about switch cases but they can't be used everywhere no?
They're not bad if you need them, but sometimes they're just unnecessary. For example, you could replace the code at 5:15 with the following: Create a Vector2 from horizontalMove and verticalMove zero the smaller component (and save the larger one) if abs(saved_component) > threshold: call MovingPlayer with vetor2.normalized and saved_component It's 2 if statements instead of 10. And there's a lot less code to read and figure out.
If statements are a necessity in game design as many situations requires comparison, but when there are duplicate statements that leads to the same result, there is likely a way you can combine them. There are times where other built-in functions can be used to narrow down statements like what @johnsmith34 provided is a perfect example. Don't worry too much on optimizing if and switch statements when starting off as there are other heavy functions that affects performance way more than that.
Code readability should also be a consideration. It's easy to read if statements. If it takes me multiple minutes to deduce what your code is doing because you used syntactic tricks to write shorter lines of code instead of using if statements, that's not good code
I am making a mobile game where i need to check tile for info i just named the tiles by the id number and check gameobject name and compare to a for loop lol.
You may have screwed up code wise but you more than made up for it in the monetization system of your game. I don't play as much as i used to, but it's one of the few mobile games ive actually gone and spent money on simply because it was so user friendly that i felt compelled to support the game regardless Bonus points for having a super addictive gameplay loop. It got pretty stale after a few hundred hours and when i ran out of characters to max, but honestly the fact that it captivated me for that long is crazy compared to all the slop saturating the mobile scene right now. Keep winning brother
Join the official Discord. The link is in the description, and there are forums for all sorts of builds. Players there can help you know all the achievements 👍
Yeah probably strings used in switches are not the best and you ended up with over 9000 lines scripts, provbably more single responsability scripts or some basic inheritance classes or custom interfaces whould ended more "clean", but hoenstly aside that, thats not that bad, i mean, when you need something to happens, the logic behind that could end up very messy and there is maybe a galaxy brain way to make it one line of code, but if it works it works... I'm making a deckbuilder roguelite, and you'll need to see how messed up are my scripts that handle how the UI for the card in hand behave... If i need to modify something in there i need atleast 2 hours to try understand how i made things works kekw
Thanks for the info on this. I ended up researching more on it and now know how to make switch use Enums instead of strings. Makes a whole lot more sense and makes it impossible for typos because of Enums 👍
A very useful tip I always tell juniors is "Don't write bad code. If I read any bad code during a code review, you will be fired instantly."
And it's still less buggy than RotMG, another pixel game with an entire dev team
"if" is better than an entire dev team🤔
Bro i was plying this game and i said lets watch some videos and this channel popped up
I've been recording several videos of this game for years. I'm Brazilian and I promote this game directly on my TH-cam channel. It's an amazing game.
I appreciate your help in promoting the game!
I need to strat playing Oba again, also great video
Thanks!
Now show us how hellish is the Void code. 😂
Well, good luck on optimizing that when you'll get motivated (and have time for it).
Will see if I can survive that. If I break more than I fix, it is staying the way it is lol
it's actually good practice to have 'case' breakouts for knowns and allow 'default' to catch the unknowns in an error.
As for the functions, I tend to program in such a way that if it is only called by one other function, then it doesn't become a subfunction (I put in-line), it's that simple. Yes, sometimes it leads to "huge" functions, but it's far too difficult to track what is going on if you have to jump through 20 sub functions (you can also 'region' out the pieces to collapse them anyway). When I refactor, I may find a way to reduce the code later or find multiple uses of snippets. I also don't usually let my sub functions called other sub functions, I literally want them to do a single task and be done.
im learning to make games and seeing the dev of one of the games i love talking about his mistakes and things like reffering to tutorials is great, make the whole game making thing looks less " otherwordly", thanks for share your experience o/
Despite the organization, you do good work on the game. It's gotten me through a few long car rides 👌
5:26 How do you optimize ifs?
They're like the most basic language construction, isn't it like trying to optimize addition or division?
Utilize others built-in functions before comparing values. When if else and switch are overly used, it will leave you wasting time trying to find the right condition if you needed to come back to it.
I'll make my next video about if else and switch as well as how 5:26 can be optimized.
> isn't it like trying to optimize addition or division
Divisions are slow. If you’re dividing by a power of two, bit shifts are the way to go. In cases where the divisor is a variable the compiler won’t save you, so divisions are something that absolutely can be optimized.
I watched Jonathan's brother go to the bathroom once
How do you keep that skill switch statement straight if it's all ints? There's no way you memorized all of those hundreds of skills in the game... right?
I only remember the ones for the update I currently work on. After that, I CTRL+F my profession script as I have all skill names commented along with the id below it lol
@@onebitadventure If i had to venture a guess as to why those were there is if they were to avoid a default case somewhere else in that switch statement. If that's a bad coding practice, I suppose I'm guilty too. lol
@@ScottyRichMusic That switch code was made before I even knew about default lol. No defaults in that switch statement so simply being that code I thought I knew what I was doing, but didn't X)
@@onebitadventure well if it ain't broke
Oh, nice game. Ive played it for quite a while, been running as glass cannon blood knight, much fun
Keep up the good work Jon, good vid
Lasagna is good code because it's structured.
You think the if else statements in the code is where the sins are committed... Actually you using magic numbers constantly and using strings in switch cases is 100x the crime. Just create variables for the numbers you use in functions and for god's sake use enums. Case "Breakable" and Case 92 isn't the correct way to do it, sure it works but many mistakes will appear while using strings in your code and you won't understand (just like in this video) what case 92 was.
But I guess you know all of this now because this game was made 5 years ago. You must have grown as a game developer. I just felt the need to say it. Your game looks quite good, have a nice journey!
i would agree that using enums would be sufficient .. but what i'm more confused about is why he didn't use ScriptableObjects for his Skills .. it would be alot easier to add and remove skills using them.
Thanks for this video. I have a few scripts that I thought were getting a little bloated. I was starting to be concerned about at what point am I going to start seeing some performance issues.
After watching this , I'm thinking I'm good to go add a few more things to those scripts with out a bit of fear lol.
Thank for your game its so good
Thank you!
Hey, just started learning programming and I don't quite understand why if statements are bad. How would you do it without if statements? Is there another option? I know about switch cases but they can't be used everywhere no?
They're not bad if you need them, but sometimes they're just unnecessary.
For example, you could replace the code at 5:15 with the following:
Create a Vector2 from horizontalMove and verticalMove
zero the smaller component (and save the larger one)
if abs(saved_component) > threshold:
call MovingPlayer with vetor2.normalized and saved_component
It's 2 if statements instead of 10. And there's a lot less code to read and figure out.
If statements are a necessity in game design as many situations requires comparison, but when there are duplicate statements that leads to the same result, there is likely a way you can combine them. There are times where other built-in functions can be used to narrow down statements like what @johnsmith34 provided is a perfect example. Don't worry too much on optimizing if and switch statements when starting off as there are other heavy functions that affects performance way more than that.
thanks guys;)
Code readability should also be a consideration. It's easy to read if statements. If it takes me multiple minutes to deduce what your code is doing because you used syntactic tricks to write shorter lines of code instead of using if statements, that's not good code
Hopefully my game isn't warcrimes
warzone dev should learn from you 5:33
I am making a mobile game where i need to check tile for info i just named the tiles by the id number and check gameobject name and compare to a for loop lol.
im the coder police, you are charged with fixing the code of onebit adventure >:(
do you understand
You will never catch me! 🏃♂️
You may have screwed up code wise but you more than made up for it in the monetization system of your game. I don't play as much as i used to, but it's one of the few mobile games ive actually gone and spent money on simply because it was so user friendly that i felt compelled to support the game regardless
Bonus points for having a super addictive gameplay loop. It got pretty stale after a few hundred hours and when i ran out of characters to max, but honestly the fact that it captivated me for that long is crazy compared to all the slop saturating the mobile scene right now.
Keep winning brother
Can anyone help me like tips how to get all achievements and wat is the best class and all u know i love this game but its little hard
Join the official Discord. The link is in the description, and there are forums for all sorts of builds. Players there can help you know all the achievements 👍
Hmm I recognise this voice 🤔
Definitely sounds familiar 🤔
Yeah probably strings used in switches are not the best and you ended up with over 9000 lines scripts, provbably more single responsability scripts or some basic inheritance classes or custom interfaces whould ended more "clean", but hoenstly aside that, thats not that bad, i mean, when you need something to happens, the logic behind that could end up very messy and there is maybe a galaxy brain way to make it one line of code, but if it works it works...
I'm making a deckbuilder roguelite, and you'll need to see how messed up are my scripts that handle how the UI for the card in hand behave...
If i need to modify something in there i need atleast 2 hours to try understand how i made things works kekw
Thanks for the info on this. I ended up researching more on it and now know how to make switch use Enums instead of strings. Makes a whole lot more sense and makes it impossible for typos because of Enums 👍
@jonathanconcepcion8215 nice to hear, good job!
I would love a beta version of dungeo of greed for android
OBA is very fun. But it is becoming stale.
10/10 video
Yeet! Killa Video!