There are conventions relating to punctuation before the dialogue/quotation and after the dialogue/quotation.
Before the dialogue/quotation:
If a signal verb is used before a quotation or a dialogue tag before dialogue, a comma is often needed.
The signal verb/attribution/dialogue tag is the verb that indicates that someone is vocalising something, e.g.
I said, “I will survive no matter what.”
She asked, “Aren’t you sick of living like this?”
“You can’t go on like this,” he proclaimed.
I was the sure that I heard the crocodile hungrily mutter, “Dinner time.”
If the signal verb/attribution/dialogue tag comes before the dialogue/quotation, then a comma is needed between the signal verb/attribution/dialogue tag and the dialogue/quotation, e.g. I wheezed, “Why won’t you leave me alone?”
If the word that comes between the signal verb/attribution/dialogue tag and the dialogue/quotation, no comma is needed, e.g. She reassured me that “Crocodiles don’t live forever.”
After the dialogue/quotation:
There always needs to be punctuation inside the final quotation marks.
If the punctuation finishes the whole whole sentence (i.e. if it ends both the dialogue/quote and whatever else is in your sentence), the punctuation must be a full stop, question mark or exclamation mark, e.g.
He said, “You should just shoot the crocodile.”
She asked, “Why don’t you just throw your brother in front of it?”
I screamed, “Run for your life!”
If the punctuation works to signal just the end of the dialogue/quote and your sentence continues after the dialogue/quote, there must be a comma inside, e.g. He said, “You should just shoot the crocodile,” but that shows that he doesn’t really understand how nimble a crocodile is.