Scripting Advice
by Anthony P · in Torque Game Engine Advanced · 12/06/2009 (12:03 pm) · 0 replies
Being new to TGEA and TorqueScript, I thought I would create a thread for scripting advice.
If there is another resource for something like this please let me know, but here is what I am hoping to accomplish. Sometimes there are better ways to find 1 + 1 = 2. So this thread would be a place to paste code snippets for optimization. I don't think this is the place to put full files, but if you have a function that just feels dirty, or learned some new scripting and think you should be able to fix old code, this is a place to have those with experience help us out.
So... here is the first one, from me.
I was playing with some AI stuff and my original code is the following
At the time I wrote it, I didn't know anything about vectorAdd (don't laugh, I told you I'm new)
I am assuming that I don't need to do the loop and can use a vectorAdd to get the same result... Which is to get a random position that is +/-40 points in both x and y.
If there is another resource for something like this please let me know, but here is what I am hoping to accomplish. Sometimes there are better ways to find 1 + 1 = 2. So this thread would be a place to paste code snippets for optimization. I don't think this is the place to put full files, but if you have a function that just feels dirty, or learned some new scripting and think you should be able to fix old code, this is a place to have those with experience help us out.
So... here is the first one, from me.
I was playing with some AI stuff and my original code is the following
function AIPlayer::getNextPlace(%this)
{
for(%i = 0;%i < 6;%i++)
{
%whereArray[%i] = getWord(%this.getTransform(),%i);
}
%addLessX1 = %whereArray[0] - 40;
%addMoreX1 = %whereArray[0] + 40;
%nextXPos = getRandom(%addLessX1,%addMoreX1);
%addLessY1 = %whereArray[1] - 40;
%addMoreY1 = %whereArray[1] + 40;
%nextYPos = getRandom(%addLessY1,%addMoreY1);
return %nextXPos SPC %nextYPos;
}At the time I wrote it, I didn't know anything about vectorAdd (don't laugh, I told you I'm new)
I am assuming that I don't need to do the loop and can use a vectorAdd to get the same result... Which is to get a random position that is +/-40 points in both x and y.