Posts: 2,938
Threads: 162
Joined: May 2010
I do 2 things to avoid this issue
1. Create a textdraw wrapper.. aka a textdraw with id 0 for player texts and server textdraws, so incase anything happens, it will try to destroy id 0. (which is the invisible unused textdraw)
2. Initilize textdraws as INVALID_TEXT_DRAW (INVALID_PLAYER_TEXT_DRAW)
3. On destroy, set the textdraw variable to INVALID_TEXT_DRAW (INVALID_PLAYER_TEXT_DRAW)
works perfect.
Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
To prevent having to init the var/arrays it'd probably be easier just to skip ID 0 (create a textdraw that is never shown and never deleted). Then in a hooked function if you try to delete ID 0 just deny it. That'd save initializing variables.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Why is that better? You lose a text draw slot and have to run custom code in the destruction function, instead of using an in-built compiler feature that's takes half a second to use.
Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
Yeah I know, I'm not even sure if I want to be a programmer anymore. I have a lot to learn.
(I edited my post, original post was something like 'I like to script things simply not complicated').
Anyway - off-topic.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Quote:
Originally Posted by Slice
Here's a little include I wrote to initialize multi-dimensional arrays. So far it's very simple, but I might add some more features and officially release it.
|
I was wondering if you would do that (I was tempted after I saw your Useful Functions post). Nicely done (though I'm not sure how the mutli-line declaration you've used in that example will work, but I've not looked closely).
Posts: 1,831
Threads: 69
Joined: Mar 2008
Reputation:
0
I settled for prepending "stock @_Ar<ARRAY NAME>" so the list either carries on or stops by a semi-colon.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Ahh. Something I have tried to solve numerous times (well, one of the things I'm constantly mulling over in the back of my mind) is if it's possible to detect HOW the variables were declared, so instead of "stock" you could put "new" or "static const" there based on what was first typed.
Posts: 586
Threads: 16
Joined: Mar 2008
Reputation:
0
As i see it, this does explain an issue based on the following circumstances:
PlayerX is playing...
Server restarts...
PlayerX crashes...
PlayerX connects...
When that happens a GPS textdraw i made looks a bit weird, but the script fixes that when the player spawns.
This is because the textdraw string for that player does not initialize correctly, Even tho i have a proper use of TextDrawDestroy in OnGameModeExit and OnPlayerDisconnect.
Instead of showing "] ] ]". It actually shows nothing, so either the textdraw string is initalized as null or a string with characters that does not show up in a textdraw. E.g: space, underscore, etc.
[HLF]Southclaw
Unregistered
I had this problem, in my gamemode I simply set all text-draws and player text-draws to be created on OnGameModeInit and destroyed on OnGameModeExit, this works well enough. It's best to just avoid creating/deleting them in runtime in my opinion.
The only problem I have is if I do this:
Start server
Load a filterscript with textdraws
Restart the server
Then I get problems with gamemode textdraws taking instructions from filterscripts.
But then again I only load and de-load filterscripts for testing purposes, when my gamemode is hosted the only filterscript won't have any GUI, all the main stuff is in the gamemode.