#Code feedback
1 messages · Page 1 of 1 (latest)
This works too
whats this?
temporary thread
ooh
You can post it in here
alr
It really doesn't matter where you post it in the end I think
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
So do you want a full code review or just the comments?
don't comment what something does, it should be self-evident.
always comment why something exists, if it's not self-evident.
Because I have a lot of tips when it comes to other stuff
🤔
id rather see if the labeling is fine first i think
but i enjoy learning tips and tricks aswell
oh hey, theres more of em
Desperately need to use else and else if in a bunch of cases
on the keydowns?
I'm not an expert but why are you using the legacy input manager?
the LaserSwitch checks, only 1 can be true so use a switch statement or else if
imma be honest, you are gonna have to explain what that is
google Unity New Input System
codeMonkey did a cool tutorial on it
The createLaser functions are indentical, they should just be one method with different parameters
saves you a lot of headache down the line
You really need to create methods for common checks rather than putting labels down.
Stuff like this is also kind of unneeded to add, considering "gameOver" is pretty clear.
//Game Reset
if (gameOver == true)
{
...
Just methods in general are a good thing to start with
Your whole Update method is full with code that should probably be seperated for example
It's the kind of thing that adds self-documenting code and is generally more readable
they're the same bc they haven't been fully used, they currently just fire, i have damage and other things to add😅
Still, you could move the shared portion of them into a method
Code feedback
It's also weird that this is called Hero_Movement but does many other random things
And maybe another tip: guard clauses!
You have methods like this
void createLaser()
{
// Base Laser code
if (!gameOver)
{
...
}
}
And you could add a guard clause and remove nesting from this, making it more readable.
void createLaser()
{
if (!gameOver) {
return;
}
...
}
I like to write my code in a way where the "positive ending" to it is always at the bottom. This helps a lot with it.
it was going to be split into 3 scripts, couldnt figure out how to reference other scripts to get the laser system to work
that example gets better when you add more stuff though, fused
then you could rename it to smth more specific
like return gameover, else fire?
Also, be consistent about capitalisation. The C# (and modern Unity standards) say public fields/properties should be PascalCase, you have a number of camelCase names.
Methods are also meant to be PascalCase.
return; like this returns nothing, if that is what you mean? It ends the method effectively.
its still gonna split, just gotta figure out my referencing
If your method returns void, you can do this
ah, thats really helpful actually
whats pacal and camal case?
If your method returns something, you obviously need to supply a return value
You can also return null in some cases, but that's specific to the return type. It means "no value". Not everything can use this.
so why does return get mad at me when i try to return specific stuff such as when i tried to return the laserswitch variable?
I'm guessing the types are not matching? For example, it expects a string and you pass an integer?
said return cannot be used to do so and so
If you share the code we can tell probably
Sounds like the problem is fixed then 😛
that's a bit off-topic but i think it'd be good if you went through CS50
yeah, i removed return and used the 1 2 3 keydowns
that college?
or did i click wrong link
pulled up harvard😂
yeah, the free course
starts may 12?
no, just use the last recorded one
hold on..
ill look into it
i kinda agree that it's better to try stuff you learn immediately but so far i haven't seen anything in unity that does that in a well-structured way
godot has gdquest so if you don't have the patience to go through the course then it might be better
while i have ya, i do have a code question
did the version of my code have the r keydown reset?
?
it did, perfect
i am intending to make a system where once the player dies, they need to press r to restart, but it needs to set the player back at the start and reset everything
not quite sure how to go about it yet
any tips that i could try/start with?
if it's not procedural, probably easier to just reload scene
what makes procedural?
i can use the starting x position as the restarts translating position i think, ill just see what i can do with that for now ig
when spawning everything that can change through code
e.g. bioshock 1 had a system that used both kind of save, one is just fresh reload of everything from last save point, and another is just respawn player without changing enemies and loot
oh i have no idea how to mess with saves and stuff... Ive been struggling tjust to get what i have and still messed up spawning the enemy
procedural is like... vampire: survivors, for example. it just spawns enemies randomly so it doesn't need to reset them, game over would instead remove all enemies and just spawn them again when needed
even then, it'd probably be more appropriate to just reload scene anyway
alr, ill be more specific, on r keypress if the game is over, ill reset the health, kill the enemies and restart their spawning, return the hero to its starting position, and reset the score
currently, i can do most
is there anything that would make reloading scene a bad idea?
returning the character to the start and getting the spawn to work is having issues
reloading scene?
you can google that, it's essentially same thing as exiting and entering play mode
ya couldn't restart the game in game?
it's just simpler and more fail-proof
"DontDestroyOnLoad" for the stuff that persists between each death
only the enemies spawn so far, id share a demo for ya, but ive no clue how publishing works yet
ill learn publishing in a week or 2 maybe
take your time, itch makes it really easy though
especially if you use webGL and don't need save system
i dont
on both ends
if it's a small game then i recommend switching early, you know that people are too lazy to download stuff
save system is annoying because it breaks between versions unless you use a workaround
im only going to share the game to a few select people, my pc wont handle much more than what im doing anyhow
workaround such as the file creation system where code can write and read on a text file?