| Home Page | Recent Changes | Preferences

# WUtils

> Latest version: 105

> [download the latest version]

UT2003 has a nice set of methods and structures defined in XGame.xUtils, but there are more common used methods and don't need to be rewritten every time somebody needs them. That's why I've started wUtils to create a package containing another set of usefull methods.

Feel free to contribute more usefull methods to this package.

You are completely free to use wUtils and distribute it with your mod. You may also use only part of the code of wUtils. You are not allowed to distribute a changed version of wUtils under the same name, this is to prevent confusion.

Note: if you use wUtils in your mod, please check to this page to check if there's a newer version available before you release the mod.

Note 2: feel free to contribute methods/classes/... you think should belong into this package.

## Usage

To use the methods from wUtils place wUtils in your EditPackages list.

Then call the methods via:

    class'wUtilsClass'.static.method()

for example:

    mystring = class'wString'.static.Trim(mystring);

## Classes of wUtils

### wString

function string Capitalize(coerce string S) (v101)
  will change "this is a string" to "This Is A String"
function Eat(out string Dest, out string Source, int Num) (v104)
  Moves NUM lements from Source to Dest
function string FloatToString(float Value, optional int Precision) (105)
  Converts a float to a string
function int InStrFrom(coerce string StrText, coerce string StrPart, optional int OffsetStart)
  like InStr except you can specify where to start the search.
function bool IsLower(coerce string S)
  check if a string is all lowercase
function bool IsUpper(coerce string S)
  check if a string is all uppercase
function string Lower(coerce string Text)
  like Caps but lowers strings
function string LTrim(coerce string S)
  trims leading spaces/tabs
function bool MaskedCompare(coerce string target, string mask, optional bool casesensitive)
  check target using mask, mask can contain the following wildcards: * for X chars, or ? for 1 char, check [MaskedCompare|my source]] if it can be optimized. There's a a bug in this function. It's fixed with v104.
function string ReplaceInString(coerce string src, int from, int length, coerce string with) (v102)
  replaces part of a string: `ReplaceInString("A stupid string.", 2, 6, "good") == "A good string."`
function bool ReplaceOption(out string Options, string Key, string NewValue, optional bool bAddIfMissing, optional out string OldValue, optional string delim)
  Allows you to quickly change a value in the Options string used in Login and PostLogin. (Source)
function int Split2(coerce string src, string delim, out array<string> parts, optional bool ignoreBlanks, optional string quotechar) (v101)
  fixed version of split. Fixed: first char can be a delim, last char can be a space. Added: delim as a string. Added: ignoreblanks: "||" results in an empty array, and quotechar. (v103)
function string StrShift(out string line, string delim, optional string quotechar)
  this will shift the first element of the line (delimited by delim). fixed: delim can be longer that 1 char (v101) added: optional quote char so you can use: "one item" "second item" (v103)
function string StrSubst(coerce string target, optional string r0, optional string r1, ... , optional string r9) (v102)
  StrSubst will replace the occurances of %s in target with the value of r#, where # is the n'th occurance of %s
function string StrReplace(coerce string target, array<string> replace, array<string> with, optional bool bOnlyFirst)
  string replace that accepts arrays, usefull if you want to implement a bad word filter, optional bOnlyFirst added in v101
function string RTrim(coerce string S)
  trims trailing spaces/tabs
function string Trim(coerce string S)
  trims leading and trailing spaces/tabs

### wMath

function int CRC32(coerce string Text, int CrcTable[256]) (v101)
  calculate the CRC32 hash of a string, more info: CRC32
function CRC32Init(out int CrcTable[256]) (v101)
  init function to call (once) before you use CRC32
function bool IsInt(coerce string Param, optional bool bPositiveOnly)
  checks if param is an integer
function bool IsFloat(coerce string Param, optional bool bPositiveOnly)
  checks if param is a float (or int)
function int PowerMod(int C, int D, int N) (v102)
  this will calculate `x^e mod y`
function RSAEncode(coerce string data, int E, int N, out array<int> data2) (v102)
  encode data using the keys E and N, RSA
function string RSADecode(array<int> data, int D, int N) (v102)
  encode data using the keys D and N, RSA
function int RSAPublicKeygen(int p, int q) (v102)
  calculate encode key using primes P and Q, RSA
function int RSAPrivateKeygen(int E, int p, int q) (v102)
  calculate decode key, RSA

### wArray

function array<int> AddI(array<int> A, array<int> B)
  join the two arrays
function array<float> AddF(array<float> A, array<float> B) (v104)
  join the two arrays
function array<object> AddO(array<object> A, array<object> B)
  join the two arrays
function array<string> AddS(array<string> A, array<string> B)
  join the two arrays
function int BinarySearch(array<string> Myarray, string SearchString, optional int Low, optional int High, optional bool bIgnoreCase) (v103)
  searches a sorted array for a matching element, returns the index if found or -1
function string GetCommonBegin(array<string> slist) (v103)
  returns the common beginning of elements in the array
function string Join(array< string > ar, optional string delim, optional bool bIgnoreEmpty)
  join the array elements to a string using delimiter 'delim', added the optional bIgnoreEmpty (v101). bIgnoreEmpty was fixed in (v104)
function float ShiftF(out array< float > ar) (v104)
  shift the first element of an float array
function int ShiftI(out array< int > ar)
  shift the first element of an int array
function object ShiftO(out array< object > ar)
  shift the first element of an object array
function string ShiftS(out array< string > ar)
  shift the first element of an string array
function array<int> RemoveI(array<int> A, array<int> B)
  remove elements in B from A
function array<float> RemoveF(array<float> A, array<float> B) (v104)
  remove elements in B from A
function array<object> RemoveO(array<object> A, array<object> B)
  remove elements in B from A
function array<string> RemoveS(array<string> A, array<string> B)
  remove elements in B from A
function SortI(out array<int> ar)
  sort an int array
function SortF(out array<float> ar) (v104)
  sort an float array
function SortS(out array<string> ar, optional bool bCaseInsenstive)
  sort a string array
function int MaxI(array<int>) (v101)
  get the highest value of an arra
function int MaxF(array<float>) (v104)
  get the highest value of an arrayy
function string MaxS(array<string>) (v101)
  get the highest value of an array
function int MinI(array<int>) (v101)
  get the lowest value of an array
function int MinF(array<float>) (v104)
  get the lowest value of an array
function string MinS(array<string>) (v101)
  get the lowest value of an array

### wTime (v104)

    struct DateTime
    {
      var int year,month,day,hour,minute,second;
    };

function string date(string format, optional int year, optional int mon, optional int day, optional int hour, optional int min, optional int sec)
  format a time to a string
function string date2(string format, DateTime dt)
  same as date but uses a DateTime as input
function DateTime duration(int seconds)
  returns the duration broken down into minutes/ hours/ days/ months/ years
function bool isLeap(int year)
  Returns true if it's a leap year
function mktime(int year, int mon, int day, int hour, int min, int sec)
  create a unix timestamp
function int SpanSeconds(DateTime Later, DateTime Earlier)
  number of seconds between both times
function DateTime Stats(int seconds)
  returns how many years/months/days/hours/minutes and x number of seconds is

### wDraw (v104)

(source at Wormbo/wUtils)

    struct MaterialRegion {
        var Material Tex;
        var IntBox TexCoords;   // absolute material coordinates
        var FloatBox ScreenCoords;  // relative screen coordinates
        var Actor.ERenderStyle RenderStyle;
        var Color DrawColor;
    };

function DrawDecimalNumberAt(Canvas C, float Value, float X, float Y, optional bool bClipped, optional int Precision)
  Draws a float value. The coordinates specify the upper left corner of the decimal point character, i.e. when you specify the upper right corner of the screen the decimal point would not be visible. added optional int Precision and fixed draw position getting changed (v105)
function DrawMaterialRegion(Canvas C, MaterialRegion M, optional float ScaleX, optional float ScaleY, optional bool bClipped)
  Draws a MaterialRegion to a Canvas. The canvas' clipping region (determined by OrgX/Y and ClipX/Y) is used to convert the MaterialRegion's screen coordinates. If ScaleY is omitted, ScaleX is used for both directions. If ScaleX is omitted, a value of 1.0 is used.
function FloatBox GetActorBox(Canvas C, Actor A)
  Calculates a box around an actor in relative screen coordinates.
function ResetClipRegion(Canvas C)
  Resets the canvas' clipping region.
function SetClipRegion(Canvas C, FloatBox ClipRegion)
  Sets the canvas' clipping region, i.e. OrgX/Y and ClipX/Y. Uses a FloatBox like it is returned by the GetActorBox method.
function DrawBracket (Canvas C, float width, float height, float bracket_size) (v105)
  This function is a corrected version of the function with the same name in the Canvas class.

## Downloads

[Release 100] (includes source)

[Release 101] (includes source)

[Release 102] (includes source)

[Release 103] (includes source)

[Release 104] (includes source)

[Release 105] (includes source)

### CVS access

If you want bleeding edge you can pull the latest version from my CVS

CVS Web Repository
  http://el-muerte.student.utwente.nl/cgi-bin/cvsweb/UT2003/wUtils
CVS Root for anonymous access
  :pserver:anonymous@el-muerte.student.utwente.nl:/usr/local/cvsroot/UT2003

## Discussion

Johnny_o: Hey, I tried using wUtils cause it will handle what I need to get done, but I can't get it to work. I setup my edit packages and call the functions just like described above. Since I don't see anyone else writing anything I assume I must be the only person with this problem and I did something wrong. Anyone know what it could be?

Wormbo: "My car doesn't move, what's wrong?" Can you be a little more specific, please?

Johnny_o: Sure, no problem. When I compile, I get the error message,

"Error: Can't find class 'wString'. I call the function I want to use like this:

    // SomeClassOfMine ------------------------

      size = class'wString'.static.split2 (...);

    // UT2003.ini -----------------------------
      ...
    EditPackages=SkaarjPack_rc
    EditPackages=OGGPlayer
    EditPackages=wUtils

I thought, "maybe I didn't set it up right." I have the wUtils.u file in the UT2003\System directory. Same error. I tried changing the call to class'wUtils.wString'.static.someFunction() and that didn't do anything. I tried recompiling wUtils, and that didn't do anything. I still get the same error I listed above. Somebody, please help!

Mychaeel: Where is your own package listed in the EditPackages list?

Johnny_o: My own package is listed a few above it. So, do I have to put wUtils above my own package before I can use it?

Mychaeel: The packages listed in the EditPackages list are loaded (and compiled) in the order they're listed in. So, in order to be able to access classes from the wUtils package, it has to be listed before your own package.

Category Custom Class

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In