SA-MP Forums Archive
Hi any idea why do we do this? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Hi any idea why do we do this? (/showthread.php?tid=578091)



Hi any idea why do we do this? - Ritzy2K - 16.06.2015

Hello!

im wondering from quite long why do we destroy textdraws OnGameModeExit while the textdraws will destroy themself when gamemode shuts.

About more i asked in scripting help. didnt got any satisfying reply. consider reading this too thanks!

https://sampforum.blast.hk/showthread.php?tid=577707


Re: Hi any idea why do we do this? - theYiin - 16.06.2015

So you can restart gamemode with rcon command gmx, without recreating same textdraws on top of the old ones.

EDIT: nvm, it's not true, I just tested it, and indeed global textdraws are destroyed automatically when gamemode exists, not when server closes.


Re: Hi any idea why do we do this? - Ritzy2K - 17.06.2015

Oh thanks for your efforts mate


Re: Hi any idea why do we do this? - Ritzy2K - 27.06.2015

bump ._.


Re: Hi any idea why do we do this? - Youssef221 - 27.06.2015

I destroy those textdraws so they don't bug when I restart the server (for me).


Re: Hi any idea why do we do this? - Ritzy2K - 27.06.2015

How will they even bug? when the gamemode exit arent they suppose to destroy themself? and when the gamemode intialises again they ll re create themself?


Re: Hi any idea why do we do this? - Jonny5 - 28.06.2015

its common practice to run "clean up" code when exiting any app.

its simple if you dont want to destroy them then dont...
if the abstract machine("server") gets shut down surly everything will be closed/destroyed.

I still will destroy mine.


Re: Hi any idea why do we do this? - Ritzy2K - 28.06.2015

What makes the difference if i destroy or not tho? (im not taunting or trolling)

I just need to make sure my coding practices are as optimized as they can be.


Re: Hi any idea why do we do this? - 2KY - 28.06.2015

Quote:
Originally Posted by [ND]xXZeusXx.
View Post
What makes the difference if i destroy or not tho? (im not taunting or trolling)

ill start up with an rpg script soon this year which will have lot of textdraws... so i want it to be completely optimized and stuff like that.
Okay, say you have 10 textdraws. For some reason, your server crashes, shuts down, restarts, whatever - and for some reason, only 4 textdraws get destroyed. When your mode starts up again, it's going to create all 10, this leads to either a) misplaced textdraw ID's or b) multiple textdraws for one ID. Either of these options aren't good, and should be prevented, which destroying them on exit does. As stated above, in programming a common practice is to run clean up code after an operation is finished.


Re: Hi any idea why do we do this? - Mauzen - 29.06.2015

Quote:
Originally Posted by 2KY
View Post
Okay, say you have 10 textdraws. For some reason, your server crashes, shuts down, restarts, whatever - and for some reason, only 4 textdraws get destroyed. When your mode starts up again, it's going to create all 10, this leads to either a) misplaced textdraw ID's or b) multiple textdraws for one ID. Either of these options aren't good, and should be prevented, which destroying them on exit does. As stated above, in programming a common practice is to run clean up code after an operation is finished.
Afaik theres no way to restart the gamemode in the same server process after a fatal crash. If the gamemode doesnt shut down properly (deleting all the textdraws) it also wont start up again, unless the server is restarted.

I guess its some placebo code, or a code artefact. There shouldnt be a scenario in which you need to "clean up" the textdraws manually on gamemode exit.
Different story for filterscripts though. Properly deleting textdraws in filterscripts is important, especially for filterscripts that are supposed to be stopped/restarted frequently, else it will create the same textdraws again and again.
So deleting textdraws in gamemodes probably comes from that. People just copied over some filterscript textdraws, and also added the cleanup part without further thinking about why they are doing it. Others might then have learned from those gamemodes, and took over that "scripting technique" for textdraws in gamemodes. Not because they need to do it, but because many other people did so before.