How to improve this code?
I got this code that reads steam ids from a config file.
After that when you plant/defuse the bomb, the plugin will check the steamids stored in the cfg and print in chat a message. Like: your steamidxxx -> [tag/etc] Player planted the bomb non steamidxxx from -cfg -> Player planted the bomb... But what if I want to use this for other functions? I always need to copy/paste the same function? Isn't this a mistake? How to improve this? PHP Code:
|
Re: How to improve this code?
If you want to call the same code again, you just need to create a private function with the shared code, and calling it in both forward.
And by the way: Trim() should be called before the check. TrieGetCell() -> TrieKeyExists ; since you don't need associated value. Call TrieDestroy() on plugin_end() forward. set_fail_state() can format string, but not sure in what AMXX version it's available. |
Re: How to improve this code?
Quote:
Quote:
|
Re: How to improve this code?
With 1.8.2, It's designed like: at map change the handle system is well freed, but not the actual allocated memory from plugin datas, which will be reused (or extented) if needed. In others words, if you allocate x bytes from plugin A, and this plugin is disabled on next map, you will have x bytes allocated for nothing.
With 1.8.3, the trie natives are no more based on KTrie library but on Hashmap instead, the whole system is different and this time, memory should be freed properly at each map change. Still, it's a good practice to free always when you can something you have previously allocated. I would recommend to use always in this context TrieDestroy in plugin_end(). |
Re: How to improve this code?
I don't know what you're doing within the loop in bomb_planted, but it's wrong.
|
| All times are GMT -4. The time now is 21:17. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.