SimSets vs. Arrays
by Jake Callery · in Torque Game Builder · 06/14/2009 (10:22 am) · 7 replies
Ok, so I read in the docs, that I should be able to use a SimSet most of the time to keep a list of things. I would like to be able to do this, since I don't seem to be able to get the count of an array.
However, I want to store a list of positions, and I don't seem to be able to do this with a SimSet...
What Works:
(for this I need to define the length.. which isn't cool)
What Doesn't work:
I realize that those strings are not "SimObjects" so they can't go into a sim set, but I was hoping it worked..
How should I be managing a list of things?
Thanks for the help!
However, I want to store a list of positions, and I don't seem to be able to do this with a SimSet...
What Works:
(for this I need to define the length.. which isn't cool)
$PosArrayLength = 3; $PosArray[0] = "-43 -30"; $PosArray[1] = "-43 0"; $PosArray[2] = "-43 20";
What Doesn't work:
$PosList = new SimSet(PosListSet);
$PosList.add("-43 -30");
$PosList.add("-43 0");
$PosList.add("-43 20");
echo("Count: " @ $PosList.getCount());I realize that those strings are not "SimObjects" so they can't go into a sim set, but I was hoping it worked..
How should I be managing a list of things?
Thanks for the help!
#2
Any ideas on what else I can search for?
06/14/2009 (2:34 pm)
Thanks for the tip.. I've been trying to find getWord in the docs in hopes of finding similar functions that might return the number of elements in a vector.. but i don't seem to be able to find the definition of getWord anywhere.. Mind you I understand how it works, but I really need to return the number of items in an array/vector/string whatever...Any ideas on what else I can search for?
#3
in most cases I prefer using arrays, which you can do so by
You can also have a look at this resources on creating a script Array.
Good Luck.
06/14/2009 (6:26 pm)
for string items you can do this...%str = "1 2 3 4 5 6 7 8 9"; %strCount = getWordCount(%str); %one = getWord(%str, 0); %two = getWord(%str, 1); %nine = getWord(%str, 8);
in most cases I prefer using arrays, which you can do so by
$PosArrayLength = 0; $PosArray[$PosArrayLength] = "-43 -30"; $PosArrayLength++; $PosArray[$PosArrayLength] = "-43 0"; $PosArrayLength++; $PosArray[$PosArrayLength] = "-43 20"; $PosArrayLength++;
You can also have a look at this resources on creating a script Array.
Good Luck.
#4
Thanks very much for the info!
Just out of curiosity.. where did you find getWordCount? I'm just trying to track down the correct places in the various sites to get the reference for this kind of thing...
Again, thanks for the help!
06/14/2009 (7:01 pm)
Ahh.. The script Array looks promising..Thanks very much for the info!
Just out of curiosity.. where did you find getWordCount? I'm just trying to track down the correct places in the various sites to get the reference for this kind of thing...
Again, thanks for the help!
#5
I find it hard to find documentation as well. The first place I look is the offline documentation provided with TGB. The next place I check is TDN and then I check the forums. If the above three fail me I will try a google search, usually brings me back to a forums page, then last resort I beg for help.
I find it most of the time the community will respond quickly and point me in the correct direction. Over the last few months I have been able to find most things I am looking for but every once in a while I will stumble on to something new, like getWord, and wish there was an easy way to find all the commands for TGB. As of now I have not found a way to do that.
Not sure if you are still looking but I did find some information on getWord here.
In a project I am currently working on I had some what of the same problem you have shown. What I did was define my simset like this:
$PosList = new SimSet() {};
$PosList.add(%myObject);
For the count I moved it into a new variable like this:
$PosCount = $PosList.getCount();
echo($PosCount);
The above will count the number of objects in the simset which can be used as a length. As you can see in my example I am loading objects into the simset, so I am not sure it will work for you. If the values you are loading are going to be positions you could define objects for them like this:
function objectLocation(%x, %y)
{
%myObject = new t2dStaticSprite() {
Position = "0 0";
};
%myObject.setPosition(%x, %y);
$PosList.add(%myObject);
}
Of course I have other things defined for my sprites but that is how I set their locations before adding them to my scene. Then you can perform the count function to get the total count of the simset.
Hopefully this will give you some useful information.
06/15/2009 (5:21 am)
Jake,I find it hard to find documentation as well. The first place I look is the offline documentation provided with TGB. The next place I check is TDN and then I check the forums. If the above three fail me I will try a google search, usually brings me back to a forums page, then last resort I beg for help.
I find it most of the time the community will respond quickly and point me in the correct direction. Over the last few months I have been able to find most things I am looking for but every once in a while I will stumble on to something new, like getWord, and wish there was an easy way to find all the commands for TGB. As of now I have not found a way to do that.
Not sure if you are still looking but I did find some information on getWord here.
In a project I am currently working on I had some what of the same problem you have shown. What I did was define my simset like this:
$PosList = new SimSet() {};
$PosList.add(%myObject);
For the count I moved it into a new variable like this:
$PosCount = $PosList.getCount();
echo($PosCount);
The above will count the number of objects in the simset which can be used as a length. As you can see in my example I am loading objects into the simset, so I am not sure it will work for you. If the values you are loading are going to be positions you could define objects for them like this:
function objectLocation(%x, %y)
{
%myObject = new t2dStaticSprite() {
Position = "0 0";
};
%myObject.setPosition(%x, %y);
$PosList.add(%myObject);
}
Of course I have other things defined for my sprites but that is how I set their locations before adding them to my scene. Then you can perform the count function to get the total count of the simset.
Hopefully this will give you some useful information.
#6
webclass.superquest.net/gamemaker-projects/Vickie%20Brown/documentation/referenc...
Download this, and always keep it open in background while you work ;)
06/15/2009 (1:31 pm)
Actually, you are looking for "TGB reference" (dont mix it with "torque script reference")webclass.superquest.net/gamemaker-projects/Vickie%20Brown/documentation/referenc...
Download this, and always keep it open in background while you work ;)
#7
I don't seem to have that with my install of TGB..
@Pubily, thanks for the comments and the link.. I appreciate the help!
06/16/2009 (7:01 pm)
Thanks much for the link! Was that a Doxygen generated doc?I don't seem to have that with my install of TGB..
@Pubily, thanks for the comments and the link.. I appreciate the help!
Torque Owner Mirko Topalski
All variables in torque are basically strings (even when u type a number). And if you have variable with strings divided with space - you have a vector with multiple elements.