CaptainGarbage
kiwifarms.net
- Joined
- Aug 9, 2024
The only real problem with an existence check, is if it's a lifetime problem, which is what that bug was was. The problem was that a variable was supposed to exist but at some point it got destroyed, causing the crash to happen. If you add that check there, the variable in question is not going to magically exist in order to do the check and therefore your code within the if statement will never execute. Yes it stops the crash, but it's not the right fix.This is an absolute nothing burger and absolutely does not warrant a video, but its an opertunity to gloat about his 133t programing sk1llz I suppose.
But It does raise the question of why he is even trying to deal dammage to somthing that has allready been removed from the scene? Does he have a hard coded variable for an enemy that just becomes null when it dies insted of a death state? Is it as the enemy is deloaded when moved away from? I dont know that much about the game but I got the impression that the only dammageable thing was that alien boss which you cant just walk away from right?
Im not familiar with gamemaker but in somthing like Godot the easy fix is to just enclose the method call to that enemy, within a conditional statment that evaluates as true if the object is in a state whete calling that method wont crash your game. e.g.
if myObj != null:
myObj.damage(myObj.getDamage())
Personaly I wouldnt store data for how much dammage an enemy should take inside that class, I would just pass in a value based on weapon.dmg × skillModifier , for example, and in the enemy class I would handle any adjustments to that value there.
Even if you do chose to store that value within the enemy, it is completly redundant to pass it in, you may as well just access it from within the class and avoid the getDamage() call.
So really it should look like this:
if myObj != null: myObj.damage(weapon.dmg × skillModifier)
But what do I know ive only made 2 shit games and never worked for blizzard.
Ok sperging over. I will humbly accept your autistic stickers now.
The funny thing is, from what I seen, Maldy boy didn't even solve the lifetime problem either. He just kicked the problem down the road by moving the calculation to a part of the code where it exists and uses the cached value. There's still obviously a problem somewhere else, where it's killing off something that should exist. Instead of actually fixing it, he just moves the problem around. IDK how the rest of the game is setup, but it could have actually killed the problem, like maybe he destroys everything after that mini-game anyway, and it's lifetime doesn't matter. I somehow doubt this, but it's possible.