• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] Error

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
 
Yeah it is pretty similar to SimError. I think it is a nice gesture in that it looks pretty good, but it has too many parameters to be useful. I think most people would just prefer call BJDebugMsg("Hello") or call SimError("yada yada").

Especially since all those \n's will clear all other messages, meaning you would have to scroll through your log if you were using this to debug a script.
 
Top