Including files

Hi there,

I'm having some issues with including some of my own files here. For some reason, after the first file is included (OnGameModeInit), the other files aren't included. I've tried deleting the OnGameModeInit include, and then the rest load fine. However, placing OnGameModeInit include back in, the error happens again. The code for calling in my includes are here:

#include "../include/callbacks/OnGameModeInit.pwn" // OnGameModeInit
#include "../include/callbacks/OnGameModeExit.pwn" // OnGameModeExit
#include "../include/callbacks/OnPlayerRequestClass.pwn" // OnPlayerRequestClass
#include "../include/callbacks/OnPlayerConnect.pwn" // OnPlayerConnect
#include "../include/callbacks/OnPlayerDisconnect.pwn" // OnPlayerDisconnect
#include "../include/callbacks/OnPlayerSpawn.pwn" // OnPlayerSpawn
#include "../include/callbacks/OnPlayerDeath.pwn" // OnPlayerDeath
#include "../include/callbacks/OnVehicleSpawn.pwn" // OnVehicleSpawn
#include "../include/callbacks/OnVehicleDeath.pwn" // OnVehicleDeath
#include "../include/callbacks/OnPlayerText.pwn" // OnPlayerText
#include "../include/callbacks/OnPlayerCommandText.pwn" // OnPlayerCommandText
#include "../include/callbacks/OnPlayerEnterVehicle.pwn" // OnPlayerEnterVehicle
#include "../include/callbacks/OnPlayerExitVehicle.pwn" // OnPlayerExitVehicle
#include "../include/callbacks/OnPlayerStateChange.pwn" // OnPlayerStateChange
#include "../include/callbacks/OnPlayerEnterCheckpoint.pwn" // OnPlayerEnterCheckpoint
#include "../include/callbacks/OnPlayerLeaveCheckpoint.pwn" // OnPlayerLeaveCheckpoint
#include "../include/callbacks/OnPlayerEnterRaceCheckpoint.pwn" // OnPlayerEnterRaceCheckpoint
#include "../include/callbacks/OnPlayerEnterLeaveCheckpoint.pwn" // OnPlayerEnterLeaveCheckpoint
#include "../include/callbacks/OnRconCommand.pwn" // OnRconCommand
#include "../include/callbacks/OnPlayerRequestSpawn.pwn" // OnPlayerRequestSpawn
#include "../include/callbacks/OnObjectMoved.pwn" // OnObjectMoved
#include "../include/callbacks/OnPlayerObjectMoved.pwn" // OnPlayerObjectMoved
#include "../include/callbacks/OnPlayerPickUpPickup.pwn" // OnPlayerPickUpPickup
#include "../include/callbacks/OnVehicleMod.pwn" // OnVehicleMod
#include "../include/callbacks/OnVehicleRespray.pwn" // OnVehicleRespray
#include "../include/callbacks/OnVehiclePaintjob.pwn" // OnVehiclePaintjob
#include "../include/callbacks/OnPlayerSelectedMenuRow.pwn" // OnPlayerSelectedMenuRow
#include "../include/callbacks/OnPlayerExitedMenu.pwn" // OnPlayerExitedMenu
#include "../include/callbacks/OnPlayerInteriorChange.pwn" // OnPlayerInteriorChange
#include "../include/callbacks/OnPlayerKeyStateChange.pwn" // OnPlayerKeyStateChange
#include "../include/callbacks/OnRconLoginAttempt.pwn" // OnRconLoginAttempt
#include "../include/callbacks/OnPlayerUpdate.pwn" // OnPlayerUpdate
#include "../include/callbacks/OnPlayerStreamIn.pwn" // OnPlayerStreamIn
#include "../include/callbacks/OnPlayerStreamOut.pwn" // OnPlayerStreamOut
#include "../include/callbacks/OnVehicleStreamIn.pwn" // OnVehicleStreamIn
#include "../include/callbacks/OnVehicleStreamOut.pwn" // OnVehicleStreamOut
#include "../include/callbacks/OnDialogResponse.pwn" // OnDialogResponse
#include "../include/callbacks/OnPlayerClickPlayer.pwn" // OnPlayerClickPlayer
The code inside the OnGameModeInit include is as follows:

new MySQL:connection;
public OnGameModeInit(){

	//Connect to MySQL Database
 	connection = mysql_connect(DB_HOST, DB_USER, DB_NAME, DB_PASS);
  	if(mysql_errno(connection) == 0){
	    print("Successfully connected to MySQL Database!");
	    print("Failed connection to MySQL Database!");
	return 1;
This is my first time I've tried coding in PAWN making use of splitting my code up into includes, so I suspect I'm doing something stupidly wrong here. Any suggestions would be welcome.

Many thanks.

Any suggestions on this? Been trying for hours now, to no avail

There is a certain maximum length for include paths, although I don't know it by heart. I believe it was 32 but it could be less, still. If the path is longer then it is truncated, so what the compiler sees might as well just be "../include/callbacks/OnGameMode", which obviously results in all kinds of glitchy behavior. In any case, try using backslashes instead of forward slashes.

Although I must say that separating a gamemode like that is a terrible design decision. Rather separate by functionality than by type; e.g. all house related stuff in one file and all business related stuff in another file.

PHP код:
new MySQL:connection
Global variables need to be in the main script, so all includes can use them?

Thanks for that, using blackslashes has fixed the issue.

My include file design will look like:


And then files respectively in those folders. Out of interst, why do you believe this is bad design?

With this technique, if you want to add a new functionality you have to make edits in twenty different files. This means callbacks eventually become bloated with unrelated stuff and that the functionality is spread out in all those files.

If you have one file per functionality you keep everything in one place. It also means that you can disable the entire system by commenting one include line in the main gamemode. The (hooked) callbacks in that file are clear and concise and ONLY contain the code for THAT specific functionality.

Interesting, okay. Can you use the same callback more than once though? For example, could I have OnDialogResponse in house_system.pwn and also OnDialogResponse in vehicle_system.pwn?

I thought this would not be possible

You can by hooking it:

Okay thanks. Jesus, it's gonna take me a lot of time to try and get my head round that. Very confusing to me right now haha

I've been having a look at this hooking, and well I'm struggling to get my head around it in all honesty. Could you by any chance give me a real simple example I could understand in regards to hooking callbacks?

Forum Jump:

Users browsing this thread: 1 Guest(s)