Game Development Community

Running into problems (TGE scripting - switch to C++???)

by Zachariah MacKay · in Torque Game Builder · 11/11/2011 (11:27 am) · 5 replies

So let me start off by saying Hi and introducing myself as this is my first post.

I'm an aspiring developer who recently purchased the TGB along with Torsion back in late August and have since been working on a videogame project on my own.

I've got to admit that I'm fairly novice at this stuff but a very quick learner, and have thus far been able to accomplish what I've wanted using Torque Script only.

I've read a fair bit on these forums and from what I understand, making any kind of serious game with TGB requires alteration of the source code itself, which is written in C++. I began this project with very little programming experience, but like I said, I'm a fast learner and have been able to pick up Torque Script extremely quickly.

However, I think my understanding of how exactly the TGB works might be a little murky, and I think this lack of understanding has me running into the problem I am now encountering. Up to this point, everything I've attempted I've succeeded at implementing using just Script. But recently I made a change to one of the script files by adding a number of global variables with very LONG lists of values contained within.

I have the majority of them declared in my game.cs file ex:

$QueueListAlpha = new ScriptObject (%this)
{
queue1 = $QueueListAlpha1;
queue2 = $QueueListAlpha2;
etc etc...
};

I have several of these, each containing 4000 values, which as you can see are storing global variable names which are referenced later on in functions in separate a .cs file.

The other .cs file has functions in it that like this:

function generateQueueLists ()
{
$QueueListAlpha.queue[$current] = new ScriptObject (%this)
{
slot1 = 0;
slot2 = 0;
etc etc etc..
};

And these each include 10000 values of this nature..


So .. I am sure there might be a better way to create these global variables to have such long lists, which I would already know how to do, but I think I might be running into a greater issue here. After implementing these huge lists, the project freezes up when I try to test it. Looking at the console log, it appears to freezing when it tries to compile the .cs file that creates the '10 000' lists. If this due to it trying to do too much within this script file, or if there's a problem in the game.cs file that it references, I don't know. Memory issue? Just me plain going about it the wrong way entirely? I don't know.


Am I going the wrong route by trying to have these huge lists declared in script? Is there a limit to how many lines you can have in a script file? Should I not be declaring these global variable lists in my game.cs?


Forgive me for being such a newb at this, but any suggestions or discussion would be greatly appreciated. I want to develop a better understanding of how the development for this engine should work. The logical procedures I've come up with are all sound, I'm good at figuring out algorithms and stuff like that, but I think I'm ignorant to a bigger picture here.


Thanks.

#1
11/11/2011 (5:09 pm)
You can instead of doing this
$QueueListAlpha = new ScriptObject (%this)
{
queue1 = $QueueListAlpha1;
queue2 = $QueueListAlpha2;
etc etc...
};

You can do something like this:
$QueueListAlpha = new ScriptObject(%this);

%count = 4000;
for(%i=0; %i<%count; %i++)
{
   $QueueListAlpha.queue[%i] = $QueueListAlpha[%i];
}

// and then in your other function
function generateQueueLists()
{
   $QueueListAlpha.queue[$current] = new ScriptObject(%this);

   %count = 10000;
   for(%i=0; %i<%count; %i++)
   {
      $QueueListAlpha.queue[$current].slot[%i] = 0;
   }
}

I'm not exactly sure as to what you're doing with these ScriptObject instances, but I've just shown you an alternative and less headache way of initializing dynamic fields within your ScriptObject instances. :)

As for the freezing you're probably pushing the limits of the scripting language with so many fields and so many ScriptObject instances as those will allocate system memory for each once you create.
#2
11/11/2011 (6:53 pm)
Aye the for loop as an alternative to just having the lists written out is something I've considered to help things be less cluttered.


These lists are being used to store records of object functions. I have a large number of objects and an algorithm that predicts a set of functions for each object to perform. I want these lists to store a record of the algorithms predictions.

The thing is, to have what I want, I pretty much NEED to have lists that store anywhere between 1000 - 10000 different functions records (stored as short strings).


Can you or anyone think of a way to do this without having it freeze?
#3
11/11/2011 (10:17 pm)
Probably going to require a custom torquescript exposed class just for that purpose in order to avoid the massive overhead of having so many dynamic fields and ScriptObject instances. So that your custom class could be just instanced once to store everything you could possibly need, but of course this does require C++ programming experience. :/
#4
11/11/2011 (11:23 pm)
I realize I've done something dumb.

By storing a lot of these lists inside of objects, instead of having them in script objects of their own, and by using for loops to generate the lists, I've been able to get everything I have so far in there working, and loading much, much quicker.


Looks like I don't have to get into the C++ stuff quite yet it seems.
#5
11/12/2011 (2:24 pm)
Cool that you figured out an alternative. :)