I figured an easy way to loop through wings (and possibly some other parts) would be to do something like this:
//Make this number match the last row of your "wingmodel" 2da.
const int MAX_2DA_ROW = 90;
void main()
{
object oUser = GetLastUsedBy();
int iCurrentWing = GetCreatureWingType(oUser);
int iNewWing = iCurrentWing + 1;
string s2DA = Get2DAString("wingmodel", "LABEL", iNewWing);
while (s2DA == "")
{
iNewWing++;
if (iNewWing >= MAX_2DA_ROW) iNewWing = 0;
s2DA = Get2DAString("wingmodel", "LABEL", iNewWing);
}
SetCreatureWingType(iNewWing, oUser);
//Debug/feedback lines
SendMessageToPC(oUser, "Your current wing #: " + IntToString(iCurrentWing));
SendMessageToPC(oUser, "Your new wing #: " + IntToString(iNewWing));
SendMessageToPC(oUser, "2DA name is: " + s2DA);
}
The description for the "Get2DAString" function mentions this:
// Gets a value from a 2DA file on the server and returns it as a string
// avoid using this function in loops
But the Lexicon says this:
You can now loop using this function. It will now work (or should work)
as fast as the game would itself getting information from a 2da file.
Likely, there now should be no noticable loss of speed compared to
pre-1.64. If there is loss of speed - it'll be greatly improved upon
pre-1.64.
Now the function I posted does seem to work pretty well but I do notice a tiny bit of a "hiccup" when changing the wings and it seems to be from looping through the 2da.
So I guess my questions are; Is it still considered 'dangerous' or bad to use the function in a loop? Is it better to just manual put in all the numbers to include or exclude instead of using the Get2DAString function?
Any advice greatly appreciated. Thanks.
Modifié par GhostOfGod, 13 juillet 2012 - 09:52 .