Need help understanding formula for probability that something good happens before something bad happens.
Informally, you can ignore the neutral events, because if one happens you are back where you started. You can then scale up the probabilities $p$ and $q$ so they sum to $1$, which gets the probability of something good being $\frac p{p+q}$ and the probability of something bad being $\frac q{p+q}$. Note these sum to $1$ and have the proper ratio, which should convince you.
More formally, the chance of good before bad is a string of neutrals followed by a good and the chance of bad before good is a string of neutrals followed by a bad. Again, the ratio has to be $\frac pq$ and the sum has to be $1$ because the chance of an infinite string of neutrals is $0$. If you want, you can sum the geometric series and get the same result for more work.
In the repeated trials, the only try that matters is the first one that isn't neutral. For that one, it's good before bad if and only if that one is good. The probability is then as advertised: the probability of good divided by the probability that the try matters.