Share Files Between Projects: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
m (→‎top: clean up, added orphan, deadend tags)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Tutorials]][[Category:Programming]]
{{Multiple issues|
=Overview=
{{Dead end|date=January 2024}}
{{Orphan|date=January 2024}}
}}


In the creation of a mod, sometimes it is necessary to have a "global" file that both the "client" and "hl" projects can use. To set a file that can be updated from both projects, just follow these steps:
In the creation of a mod, sometimes it is necessary to have a "global" file that both the "client" and "hl" projects can use. To set a file that can be updated from both projects, just follow these steps:


1. Browse to your mod folder, e.g. '''C:\MyMods\Mod\''' and go to the '''src''' directory. In this example, we are going to open the '''game_shared''' directory and create a new .cpp file.
#Browse to your mod folder, e.g. '''C:\MyMods\Mod\''' and go to the '''src''' directory. In this example, we are going to open the '''game_shared''' directory and create a new .cpp file.
#Create a text file by right-clicking the folder and clicking '''New -> Text Document'''. Rename it '''mysharedfile.cpp'''.
#Open up the solution file '''game.sln''' in VS.NET.
#Under the '''client''' project create a new folder under Source Files. Name it '''mod''' or whatever you prefer.
#'''Right-click the "mod" folder''' and select '''Add -> Add Existing Item'''.
#Browse to your '''C:\MyMod\Mod\src\game_shared''' directory and find '''mysharedfile.cpp'''. Double-click it to add it to your project.
#Repeat steps 4-6 for the '''hl''' project.


2. Create a text file by right-clicking the folder and clicking '''New -> Text Document'''. Rename it '''mysharedfile.cpp'''.
The point of doing this is that both projects now share the same file. This means it does NOT matter which project you use to edit your file, they will be updated and compiled by both. You can use this method for any type of file you want to share.
 
3. Open up the solution file '''game.sln''' in VS.NET.
 
4. Under the '''client''' project create a new folder under Source Files. Name it '''mod''' or whatever you prefer.


5. '''Right-click the "mod" folder''' and select '''Add -> Add Existing Item'''.
{{note|You do not have to put your shared files in '''game_shared''', it's just easier to keep organized that way. Feel free to create a whole new subfolder. Your includes might be a bit different then, e.g. <code>#include <mycustomfolder/header.h></code>.}}
 
6. Browse to your '''C:\MyMod\Mod\src\game_shared''' directory and find '''mysharedfile.cpp'''. Double-click it to add it to your project.
 
7. Repeat steps 4-6 for the '''hl''' project.
 
The point of doing this is that both projects now share the same file. This means it does NOT matter which project you use to edit your file, they will be updated and compiled by both. You can use this method for any type of file you want to share.


'''NOTE:''' You do not ''have'' to put your shared files in '''game_shared''', it's just easier to organize that way. Feel free to create a whole new subfolder. Your includes might be a bit different then, e.g. <code>#include <mycustomfolder/header.h></code>.
[[Category:Tutorials]]
[[Category:Programming]]

Latest revision as of 10:12, 21 January 2024

Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

In the creation of a mod, sometimes it is necessary to have a "global" file that both the "client" and "hl" projects can use. To set a file that can be updated from both projects, just follow these steps:

  1. Browse to your mod folder, e.g. C:\MyMods\Mod\ and go to the src directory. In this example, we are going to open the game_shared directory and create a new .cpp file.
  2. Create a text file by right-clicking the folder and clicking New -> Text Document. Rename it mysharedfile.cpp.
  3. Open up the solution file game.sln in VS.NET.
  4. Under the client project create a new folder under Source Files. Name it mod or whatever you prefer.
  5. Right-click the "mod" folder and select Add -> Add Existing Item.
  6. Browse to your C:\MyMod\Mod\src\game_shared directory and find mysharedfile.cpp. Double-click it to add it to your project.
  7. Repeat steps 4-6 for the hl project.

The point of doing this is that both projects now share the same file. This means it does NOT matter which project you use to edit your file, they will be updated and compiled by both. You can use this method for any type of file you want to share.

Note.pngNote:You do not have to put your shared files in game_shared, it's just easier to keep organized that way. Feel free to create a whole new subfolder. Your includes might be a bit different then, e.g. #include <mycustomfolder/header.h>.