Skip to content

External Libraries ‐ Errors & Warnings

Akin C. edited this page Jan 24, 2025 · 22 revisions

Errors and Warnings

📚 The libraries errors.tph and warnings.tph can be found here.

Those libraries are designed to handle warnings and errors of different kinds. It has the potential to grow as my personal demand for more features increases.

The libraries have been tested on Windows 11 and are likely to work on other operating systems, such as Linux and macOS. They may also work on older versions of Windows.

  • prefix "ERR" in "ERR_<function name>" indicates that this is an error function
  • prefix "WARN" in "WARN_<function name>" indicates that this is a warning function

ERR_EVALUATE_FILE_EXISTANCE

Since it's a dimorphic function, it can be used for outer and patching files. To call this function outside of patching, use the keyword LAF. To call it inside patching, use the keyword LPF.

Purpose: Raises a warning if the specified file exists

Parameters:

file ➡️ The name of the file to check for existence

message ➡️ The error message to display upon file existence

Example 1: Outer

// Creates a file array
ACTION_DEFINE_ARRAY files 
BEGIN 
	~dlc/sod-dlc.zip~ 
	~sod-dlc.zip~ 
END

// OUTSIDE OF PATCHING
// -------------------
OUTER_SPRINT error ~Hello World!~

// Checks all game shortcuts
OUTER_FOR (index = 0; VARIABLE_IS_SET $files(~%index%~); ++index) BEGIN

	// Gets specific file
	OUTER_TEXT_SPRINT file $files(~%index%~)

	// Calls error
	LAF ERR_EVALUATE_FILE_EXISTANCE 
		STR_VAR 
			file 	= EVAL ~%file%~
			message = EVAL ~%error%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT error @1073741823 which can be used to raise an error in different languages.

Example 2: Patch

// Creates a file array
ACTION_DEFINE_ARRAY files 
BEGIN 
	~dlc/sod-dlc.zip~ 
	~sod-dlc.zip~ 
END

// Creates a dummy item file
CREATE ~ITM~ ~Testfile~

// PATCHING ITEM TESTFILE
// ----------------------
COPY_EXISTING ~Testfile.ITM~ ~%MOD_FOLDER%~
SPRINT error ~Hello World!~

// Checks all files
FOR (index = 0; VARIABLE_IS_SET $files(~%index%~); ++index) BEGIN

	// Gets specific file
	TEXT_SPRINT file $files(~%index%~)

	// Calls error
	LPF ERR_EVALUATE_FILE_EXISTANCE 
		STR_VAR 
			file 	= EVAL ~%file%~
			message = EVAL ~%error%~
		END
END

"SPRINT" allows the use of @integer values, e.g. SPRINT error @1073741823 which can be used to raise an error in different languages.

ERR_EVALUATE_GAME_EXISTANCE

Since it's a dimorphic function, it can be used for outer and patching files. To call this function outside of patching, use the keyword LAF. To call it inside patching, use the keyword LPF.

Purpose: Raises an error if the specified WeiDU game short is detected and prevents further installation

Parameters:

game ➡️ The WeiDU game short identifier to check for installation

message ➡️ The error message to display if the specified game is detected

Example 1: Outer

// Creates an array with game shortcuts which are incompatible with mod
ACTION_DEFINE_ARRAY games_incompatible
BEGIN 
	~bg2~
 	~tob~
	~iwd2~
	~pst~
	~bg1~
	~totsc~
	~iwd1~
	~how~
	~totlm~
	~tutu~
	~tutu_totsc~
	~bgt~
	~ca~
	~iwd_in_bg2~
	~bgee~
	~bg2ee~
	~eet~
	~iwdee~
	~pstee~ 
END

// OUTSIDE OF PATCHING
// -------------------
OUTER_SPRINT error ~Hello World!~

// Checks all game shortcuts
OUTER_FOR (index = 0; VARIABLE_IS_SET $games_incompatible(~%index%~); ++index) BEGIN

	// Gets specific game shortcut
	OUTER_TEXT_SPRINT game $games_incompatible(~%index%~)

	// Calls error 
	LAF ERR_EVALUATE_GAME_EXISTANCE 
		STR_VAR 
			game 	= EVAL ~%game%~
			message = EVAL ~%error%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT error @1073741823 which can be used to raise an error in different languages.

🧭 Use this link for a complete code example.

Example 2: Patch

// Creates an array with game shortcuts which are incompatible with mod
ACTION_DEFINE_ARRAY games_incompatible
BEGIN 
	~bg2~
 	~tob~
	~iwd2~
	~pst~
	~bg1~
	~totsc~
	~iwd1~
	~how~
	~totlm~
	~tutu~
	~tutu_totsc~
	~bgt~
	~ca~
	~iwd_in_bg2~
	~bgee~
	~bg2ee~
	~eet~
	~iwdee~
	~pstee~ 
END


// Creates a dummy item file
CREATE ~ITM~ ~Testfile~

// PATCHING ITEM TESTFILE
// ----------------------
COPY_EXISTING ~Testfile.ITM~ ~%MOD_FOLDER%~
SPRINT error ~Hello World!~

FOR (index = 0; VARIABLE_IS_SET $games_incompatible(~%index%~); ++index) BEGIN

	// Gets specific game shortcut
	TEXT_SPRINT game $games_incompatible(~%index%~)

	// Calls error 
	LPF ERR_EVALUATE_GAME_EXISTANCE 
		STR_VAR 
			game 	= EVAL ~%game%~
			message = EVAL ~%error%~
		END
END

"SPRINT" allows the use of @integer values, e.g. SPRINT error @1073741823 which can be used to raise an error in different languages.

🧭 Use this link for a complete code example.

WARN_EVALUATE_FILE_EXISTANCE

Since it's a dimorphic function, it can be used for outer and patching files. To call this function outside of patching, use the keyword LAF. To call it inside patching, use the keyword LPF.

Purpose: Raises a warning if the specified file exists

Parameters:

file ➡️ The name of the file to check for existence

message ➡️ The warning message to display upon file existence

Example 1: Outer

// Creates a file array
ACTION_DEFINE_ARRAY files 
BEGIN 
	~dlc/sod-dlc.zip~ 
	~sod-dlc.zip~ 
END

// OUTSIDE OF PATCHING
// -------------------
OUTER_SPRINT warning ~Hello World!~

// Checks all files
OUTER_FOR (index = 0; VARIABLE_IS_SET $files(~%index%~); ++index) BEGIN

	// Gets specific file
	OUTER_TEXT_SPRINT file $files(~%index%~)

	// Calls warning 
	LAF WARN_EVALUATE_FILE_EXISTANCE 
		STR_VAR 
			file 	= EVAL ~%file%~
			message = EVAL ~%warning%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT warning @1073741822 which can be used to raise an warning in different languages.

🧭 Use this link for a complete code example.

Example 2: Patch

// Creates a file array
ACTION_DEFINE_ARRAY files 
BEGIN 
	~dlc/sod-dlc.zip~ 
	~sod-dlc.zip~ 
END

// PATCHING ITEM TESTFILE
// ----------------------
COPY_EXISTING ~Testfile.ITM~ ~%MOD_FOLDER%~
SPRINT warning ~Hello World!~

// Checks all files
FOR (index = 0; VARIABLE_IS_SET $files(~%index%~); ++index) BEGIN

	// Gets specific file
	TEXT_SPRINT file $files(~%index%~)

	// Calls warning 
	LPF WARN_EVALUATE_FILE_EXISTANCE 
		STR_VAR 
			file 	= EVAL ~%file%~
			message = EVAL ~%warning%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT warning @1073741822 which can be used to raise an warning in different languages.

🧭 Use this link for a complete code example.

WARN_EVALUATE_GAME_EXISTANCE

Since it's a dimorphic function, it can be used for outer and patching files. To call this function outside of patching, use the keyword LAF. To call it inside patching, use the keyword LPF.

Example 1: Outer

// Creates an array with game shortcuts whose compatibilty with the mod is uncertain
ACTION_DEFINE_ARRAY games_insecure_compatibility
BEGIN 
	~bg2~
	~tob~
	~iwd2~
	~pst~
	~bg1~
	~totsc~
	~iwd1~
	~how~
	~totlm~
	~tutu~
	~tutu_totsc~
	~bgt~
	~ca~
	~iwd_in_bg2~
	~bgee~
	~bg2ee~
	~eet~
	~iwdee~
	~pstee~
END

// OUTSIDE OF PATCHING
// -------------------
OUTER_SPRINT warning ~Hello World!~

// Checks all game shortcuts
OUTER_FOR (index = 0; VARIABLE_IS_SET $games_insecure_compatibility(~%index%~); ++index) BEGIN

	// Gets specific game shortcut
	OUTER_TEXT_SPRINT game $games_insecure_compatibility(~%index%~)

	// Calls warning 
	LAF WARN_EVALUATE_GAME_EXISTANCE 
		STR_VAR 
			game 	= EVAL ~%game%~
			message = EVAL ~%warning%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT warning @1073741822 which can be used to raise an warning in different languages.

🧭 Use this link for a complete code example.

Example 2: Patch

// Creates an array with game shortcuts whose compatibilty with the mod is uncertain
ACTION_DEFINE_ARRAY games_insecure_compatibility
BEGIN 
	~bg2~
	~tob~
	~iwd2~
	~pst~
	~bg1~
	~totsc~
	~iwd1~
	~how~
	~totlm~
	~tutu~
	~tutu_totsc~
	~bgt~
	~ca~
	~iwd_in_bg2~
	~bgee~
	~bg2ee~
	~eet~
	~iwdee~
	~pstee~
END

// PATCHING ITEM TESTFILE
// ----------------------
COPY_EXISTING ~Testfile.ITM~ ~%MOD_FOLDER%~
SPRINT warning ~Hello World!~

// Checks all game shortcuts
FOR (index = 0; VARIABLE_IS_SET $games_insecure_compatibility(~%index%~); ++index) BEGIN

	// Gets specific game shortcut
	TEXT_SPRINT game $games_insecure_compatibility(~%index%~)

	// Calls warning 
	LPF WARN_EVALUATE_GAME_EXISTANCE 
		STR_VAR 
			game 	= EVAL ~%game%~
			message = EVAL ~%warning%~
		END
END

"OUTER_SPRINT" allows the use of @integer values, e.g. OUTER_SPRINT warning @1073741822 which can be used to raise an warning in different languages.

🧭 Use this link for a complete code example.

List of @integer values

This is not implemented in the library itself, but this list of error and warning messages shows what I use in my mods. It is intended for messages that make sense in different languages. Here you can find examples of a warning tra file and an error tra file. The reason why I think this is valuable can be found here.