Function comparison
by Jeff Trier · in Torque Game Engine · 04/30/2003 (6:00 am) · 0 replies
There has been something that I haven't quite been able to get my head around...
I noticed that there are 2 ways I can call a function.
Method 1: I could call this function with fillList();.
Method 2: I could make two functions and call them with UnitList.fillList(); and ObjectLabList.fillList();.
My question is, what is the advantage of calling functions with Method 2?
I know this is a pretty basic question, but after reading through the docs and tuts, I can't figure this out. I know how to create them, I am not sure why I would. Please help me in my understanding of this.
Thanks guys!
-Jeff
I noticed that there are 2 ways I can call a function.
Method 1: I could call this function with fillList();.
function fillList(%this){
%this.clear();
if (%this == UnitList)
%filename = "fps/server/scripts/armies/armyData.cs";
if (%this == ObjectLabList)
%filename = "fps/server/scripts/armies/objectData.cs";
%LineCount = ReadListFile(%filename);
for ( %i = 0; %i < %LineCount; %i++ ){
%RowInfo = buildLineDataString($DataSheet[%i]);
%this.addRow( %i, %RowInfo, %i );
echo(%rowInfo);
echo("Unit This = " @ %this);
}
}Method 2: I could make two functions and call them with UnitList.fillList(); and ObjectLabList.fillList();.
function UnitsList::fillList( %this ){
%this.clear();
%filename = "fps/server/scripts/armies/armyData.cs";
%LineCount = ReadListFile(%filename);
for ( %i = 0; %i < %LineCount; %i++ ){
%RowInfo = buildLineDataString($DataSheet[%i]);
%this.addRow( %i, %RowInfo, %i );
echo(%rowInfo);
echo("Unit This = " @ %this);
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function ObjectLabList::fillList( %this ){
%this.clear();
%filename = "fps/server/scripts/armies/objectData.cs";
%LineCount = ReadListFile(%filename);
for ( %i = 0; %i < %LineCount; %i++ ){
%RowInfo = buildLineDataString($DataSheet[%i]);
%this.addRow( %i, %RowInfo, %i );
echo(%rowInfo);
}
}My question is, what is the advantage of calling functions with Method 2?
I know this is a pretty basic question, but after reading through the docs and tuts, I can't figure this out. I know how to create them, I am not sure why I would. Please help me in my understanding of this.
Thanks guys!
-Jeff
About the author
Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.