Jump to content

Random Player Skins WITHOUT Tab Seperated String


Recommended Posts

For some reason, tab seperated strings hate me. :?

Sometimes my custom player/aiplayers will spawn with skin set to "alt3 alt4" as the tabbed string decides to ignore the tab seperation because ... because it hates me. :cry:

A second issue with the stock skin selection is that %skin = addTaggedString( getField(%availableSkins, getRandom(%count)) ); gives the whole getCount(), but getRandom() starts at 0, meaning that it's looking for 1 more skin than is available because "base" skin is in the availableSkins string.

So I changed everything to words seperated with a space.

Player/AIPlayer datablock

   //availableSkins =  "base	alt1	alt2	alt3	alt4";
   availableSkins = "base alt1 alt2 alt3 alt4";//words not tabs


In wherever you have the randomized skin function (scripts/server/gameBase.cs is stock)

      // Choose a random, unique skin for this client
      %count = getWordCount(%availableSkins);//getFieldCount(%availableSkins);//tabs out words in
      if(%count > 0)
         %skin = getWord(%availableSkins, getRandom(%count - 1));//now with -1 for the real number
         //%skin = addTaggedString( getField(%availableSkins, getRandom(%count)) );
         echo("skins " @ %count SPC %skin);


Not entirely certain why tabbed fields were chosen over spaced words for stock but hey. :|

Link to comment
Share on other sites

Torque3D Documentation Release 3.5.1

p. 373

Field Manipulators

Functions to deal with whitespace-seperated lists of values in strings. TorqueScript excessively uses strings to represent

lists of values . The functions in this group simplify working with these lists and allow to easily extract individual values

from their strings .

The list strings are segregated into three Groups according to the delimiters used to separate individual values in the


Strings of words; Elements are separated by newlines (n), spaces or tabs (t).

strings of fields: Elements are separated by newlines (n),or tabs (t).

strings of records: Elements are separated by newlines (n)

Aside from the functions here , another useful means to work with strings of words is TorqueScripts foreach$ state-

ment .

some other page -

bool isspace (string str, int index)

Test whether the character at a given position is a whitespace character. Characters such as tab, space, or

newline are considered whitespace.


str - the string to test.

index - the index of a charcter in str

Returns true if the character at the given index in str is a whitespace character, false otherwise.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...