Writing Include Files (.inc)
So I searched the alliedmodders wiki on sourcemod code writing and haven't found much about this subject. Even the search bar is returning a lot of false positives here. Basically I have a plugin I wrote that is huge, and I originally intended to merge it with another plugin. However, since the source code is massive, I'd rather write an .inc file and use #include <filename> in the other plugin for the sake of cleanliness and maintenance.
I've seen some discussion of include files in the wiki, but it's mostly geared to how to read them, not how to write them. Suppose I have the following as a plugin (this is a purposely contrived example) PHP Code:
In other words, how do I write the inc file such that I can make all those variables/functions accessible to other plugins? If there's any article or some tutorial on this that I managed to not find, I'd gladly read that (and ask any further clarifying questions here). Thank you! |
Re: Writing Include Files (.inc)
What you looking for is creating native functions https://wiki.alliedmods.net/Creating...Mod_Scripting)
|
Re: Writing Include Files (.inc)
The only way to do what you're looking for would be to use natives or forwards (depending on the case) to pass the information along through the separate plugins.
https://wiki.alliedmods.net/Creating...Mod_Scripting) https://wiki.alliedmods.net/Function...ting)#Forwards |
Re: Writing Include Files (.inc)
Beautiful, I will read over those wiki pages. Thank you both!
|
Re: Writing Include Files (.inc)
So from reading those articles, functions can be made into natives, but there's no way of making variables visible in other plugins?
In other words, is there not a way to import handles, strings, and numeric variables from one plugin to another? Do I need to write additional natives that would, say, insert or retrieve data from the MyArray handle in the example above? (Which doesn't sound right, since if you run #include <tf2> you get the TFClass_Scout, TFClass_Soldier, etc variables included within the namespace of your file.) |
Re: Writing Include Files (.inc)
Quote:
PHP Code:
|
Re: Writing Include Files (.inc)
Quote:
So... its OK to have an enum or constant in an include file as their values never change. On the flip side, putting a variable there ends up with each plugin having their own independent copy of the variable. |
Re: Writing Include Files (.inc)
Quote:
Quote:
I suppose I'll just write a bunch of additional natives that get/set values on variables in the other plugin (like TheSpeck was mentioning). Keeping multiple copies sounds like a lot of unwanted bookkeeping work (especially if handles are involved, which it is in my case). Thanks for the responses! I'll give it an attempt tonight/tomorrow and see if it works out well. |
Re: Writing Include Files (.inc)
Be sure to post your work here if it's not a private plugin (or even just post the relevant part if it's private.) There are a few little easy mistakes that can cause major bugs that might not be noticed until AFTER plugin release.
|
Re: Writing Include Files (.inc)
You don't have a choice, you have to create native to share variables values, you can't share variables. Create get/set natives is pretty much the solution. Except if you do like events scripts and variables = console variables which I would not recommend.
|
All times are GMT -4. The time now is 17:31. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.