Game Development Community

Arrays

by Paul Fountain · in Torque Game Builder · 04/20/2006 (9:50 am) · 9 replies

I am really digging into the scripting now with T2D and for the most part, loving it. But I do have one big problem that has caused me a lot of wasted hours coding implementation details instead of coding my game:

Please, for the love of god, give us a decent array! I have now spent hours downloading and installing tools to make a debug version of T2D, messing around with someone's custom array class that doesn't work with Beta 2, fiddling with SimSets, and trying other ideas of my own, all because the arrays in TorqueScript don't allow you to count the number of items in the array, or search for an item in the array. There is no reason TorqueScript can't have a real array that allows you to add, remove, count, search, and sort painlessly. Other stuff like push and pop, etc. would just be gravy and shouldn't be that hard either. From reading through these forums, I can see that this is a problem that affects a lot of customers. So I humbly request that TorqueScript arrays get updated into the 21st century. Thank you.

/Sign it if you agree.

#1
04/20/2006 (10:10 am)
Paul - Yes, please do code a good array for us.

Cause whining about it won't get you any further then that ;)
#2
04/20/2006 (10:12 am)
I agree with Chris.
I am fine with the arrays that are there at the moment, if you think about it, and what you're trying to do, there is nothing stopping you from doing what you want with the current arrays. If there is something stopping you, then please do code a nice array. :)
#3
04/20/2006 (10:16 am)
With current arrays... SimSets... and ScriptObjects you really have all the data handling you need. If you want your data to work a specific way then add it and release it as a resource, a TGE user did that in Oct of 2003.

If you are specific to the point that you want your data to be handled differently in a way that you completely understand and have the coding skills to utilize, then you should have the coding skills to set it up :) That way you'll have it just the way you want anyways.

ADD: just wanted to add that we don 't ignore these suggestions, in fact we've taken suggestions and have enhanced TS and there have been Many talks of how to enhance it in the future. You just sound like you need something now, so add it now.
#4
04/20/2006 (11:58 am)
I have already used a SimSet to satisfy my current needs. My major frustration with using this method is the fact that a SimSet must be composed of ScriptObjects. So instead of just searching for a specific string in the SimSet, I had to write my own function to grab each object in the SimSet, and then compare that object's data member against my target string. Was it a big deal? Not really. But most every language I have worked with in the past already has an array structure that handles this stuff for you.

I don't want my suggestion or feature request to be construed as "whining", but I did pay $100 for this product which, by GG's admission, is still in alpha. And SimSets, along with a whole slew of other features, are not in the official documentation - I had to do some major searching on the forums and in the actual engine code to find out that SimSets existed and how to use them. I have the coding skills to handle this kind of stuff, but probably many T2D customers don't. The whole point of a scripting language/engine is to make my life easier.

So again, I humbly and respectfully request that TorqueScript arrays be upgraded to handle count, search, sort, and other common tasks that many other languages have. I think it would be extremely helpful to a large number of GG's customers.
#5
04/20/2006 (12:02 pm)
Paul, if you have the coding skills to handle what you want to do, upgrade your TS arrays to handle count, search, sort, and whatever other functions you want.

Then, from there you could post a resource, which would give T2D owners the chance to implement those changes and use them for themselves. :)
#6
04/20/2006 (1:56 pm)
Another option is to create a simple scritpt object class to handle this.

new ScriptObject(ArrayClass);

function ArrayClass::addString(%this, %string)
{
   %count = %this.stringCount();
   
   %this.stringArray[%count] = %string;

   %this.stringCount++;
}

etc... etc...

then just create script object using this as a class.

new ScriptObject(stringArray)
{
   class = ArrayClass;
}

then you can access the functions

stringArray.addString("blah");

etc...
#7
04/20/2006 (3:52 pm)
The array resource is working fine with me (last beta 2).
It was only hours of setup. Nothing painful (some functions were bad and it didn't
take too much to be fixed).

But, I agree with you Simsets are way expensive to storage numbers.
And it's a really shame TorqueScript don't support arrays natively.
But if you have the skills you proclaim it's simple to use the diff file I posted in the
resource comments. The resource is not mine, so I can't update the files.
And I haven't used all the methods. Maybe others thing could be wrong.

Make a script fake object? Maybe for begginers, I was thinking in using the arrayobject
for a sudoku game I was doing, (extensive use of array structures) but the time was depriment,
so I implemented all the code in C++ using [tVector] (by the way I discovered a ugly bug in the
back() method but this is another story...)

Yes $100 can be serius money, (tell me to me) but IMHO the code you have granted
worths $2M or more (just guessing), seriously sometimes I think I robed to the GG people :)
#8
04/20/2006 (5:18 pm)
Does anyone know where in the C++ source the torquescript arrays are implemented? I would like to take a look at how it's implemented ( i.e. is it a really fast dictionary/hashtable object or does it just a C array that does a dumb scan 0...n until it hits the matching "key") I've searched the C++ source but could not find it. I've asked this before in other threads, but no definitive responses. thanks in advance.

I have mucked around a bit with the script array upgrade which is a fairly popular resource but it requires compiling and care & feeding each new release of the engine, as was noted above. It also seems it continues to have unexpected bugs & crashes.

OPINION

Soon there will be a dozen resources for adding proper Collection objects (array/hashtable/sets/etc) to torquescript. What a confusing mess that will be, for new torque users, especially without any plug-in architecture to make it easier to experiment with engine mods.

/OPINION
#9
04/20/2006 (9:28 pm)
You can always use the Lua resource*. Lua has lovely tables/arrays which can be iterated, sorted, added to, removed from, can store any datatype etc. To me that sounds like what you want. *Although working with two scripting languages is also a challenge...