A stupid question about optimization
#1
Posted 02 May 2011 - 03:50 PM
Also, unticking that box means i get an error everytime i try to access a destroyed object's variables, how can i check in the most effective manner if a variable pointing to an id has the target still existing ?
Thanks
#2
Posted 02 May 2011 - 03:59 PM
The computational cost of declaring a variable is negligible. And since it is a one-time procedure, it is even more negligible. Besides, with that option on, the variable will still be declared anyways when the variable is first referenced or assigned.Simply put, unticking that box means that i need to set some variables in the create event of some objects, variables which i sometimes don't use. I'm scared that setting these variables in the create event would have a computational cost and therefore slow down the game.
But when you do have that option checked on, you can get into trouble with some very elusive bugs. Mistype a variable name and you could soon be incrementing the wrong variable without knowing it. This is why most GM experts find this option abhorrent.
Use instance_exists().Also, unticking that box means i get an error everytime i try to access a destroyed object's variables, how can i check in the most effective manner if a variable pointing to an id has the target still existing ?
GameGeisha
#3
Posted 02 May 2011 - 04:17 PM
I knew about instance exist, but some testing i've done seemed to imply it's slower then checking if the object's x position is equal to 0, so i'm not sure if i should change or not
#4
Posted 02 May 2011 - 04:22 PM
The problem is that 0 is a valid coordinate value. If you have that option checked and you get 0 from inst.x, there is no telling whether the instance is actually at 0 or just doesn't exist. This is why the way you're doing it is a bad idea.I knew about instance exist, but some testing i've done seemed to imply it's slower then checking if the object's x position is equal to 0, so i'm not sure if i should change or not
The correctness of the code is more important than small performance hits that sanity checks incur.
GameGeisha
#5
Posted 02 May 2011 - 04:24 PM
The problem is that 0 is a valid coordinate value. If you have that option checked and you get 0 from inst.x, there is no telling whether the instance is actually at 0 or just doesn't exist. This is why the way you're doing it is a bad idea.
I knew about instance exist, but some testing i've done seemed to imply it's slower then checking if the object's x position is equal to 0, so i'm not sure if i should change or not
The correctness of the code is more important than small performance hits that sanity checks incur.
GameGeisha
Nah, i'm sure that the objects i'm checking never go there ^^. However, you are right, thank you very much, i'll change my scripts
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











