Random Player Skins WITHOUT Tab Seperated String

Scripts and code that enhance the gameplay functionality of the engine.
3 posts Page 1 of 1
Posts: 344
Joined: Tue Feb 03, 2015 10:30 pm
by Steve_Yorkshire » Fri Aug 17, 2018 6:45 pm
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. :|
Posts: 1626
Joined: Sun Feb 08, 2015 1:51 am
by Duion » Fri Aug 17, 2018 7:40 pm
I noticed "\t" being used as a separator in my code sometimes, is that a replacement for the tab?
Posts: 172
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Sat Aug 18, 2018 4:48 am
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.
3 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest