- Joined
- Apr 24, 2012
- Messages
- 5,113
JASS:
//! zinc
library Error/* v1.0
*************************************************************************************
*
* Simple Error Message System with a better message format and color.
*
*************************************************************************************
*
* API
*
* public function Error(player p, string errorType, string libName, string message, real duration, boolean debugFlag, boolean clearFlag, boolean soundFlag))
* p = the player you want to show the message. If the debugFlag is true, it will convert p to GetLocalPlayer()
* errorType = Type of error you want. Choose the types from the color tags in the globals
* libName = optional,write the name of the lib or struct name you want the error corresponds.
* message = the message you want to show
* duration = duration of message
* debugFlag = optional, debugFlag has a format that shows the lib/struct name error.
* clearFlag = optional, clears messages
* soundFlag = optional, play's the error sound.
*
*************************************************************************************
*
* Credits
*
* Archange1 for the Error technique
*
************************************************************************************/
{
constant string ERROR_COLOR = "|c00FF0000",
WARNING_COLOR = "|c00FFFF00",
SUCCESS_COLOR = "|cFF34FF34";
constant real MESSAGE_X = 0.52,
MESSAGE_Y = 0.96;
sound ERROR_SOUND;
public function Error(player p, string errorType, string libName, string message, real duration, boolean debugFlag, boolean clearFlag, boolean soundFlag)
{
if (debugFlag)
{
p = GetLocalPlayer();
message = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + errorType + libName + " Error : " + message + "|r";
}
else{ message = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + errorType + message + "|r"; }
if (soundFlag)
{
if (null == ERROR_SOUND) { ERROR_SOUND = CreateSoundFromLabel( "InterfaceError",false,false,false,10,10); }
StartSound(ERROR_SOUND);
}
if (clearFlag) { ClearTextMessages(); }
DisplayTimedTextToPlayer(p, MESSAGE_X, MESSAGE_Y, duration, message);
}
}
//! endzinc
Demo:
JASS:
struct Test
static method onInit takes nothing returns nothing
local boolean b = false
if GetLocalPlayer() == Player(0) then
set b = true
endif
if b then
call Error(GetLocalPlayer(), SUCCESS_COLOR, "Test", "GetLocalPlayer is equal to Player 1", 2.0, true, true, false)
else
call Error(GetLocalPlayer(), ERROR_COLOR, "Test", "GetLocalPlayer is not equal to Player 1", 2.0, true, true, true)
endif
endmethod
endstruct