Author Topic: Utilizing Arrayobjects  (Read 1741 times)

I read some documentation about arrayobjects and they sound great. How do I utilize them?
http://docs.garagegames.com/torque-3d/reference/classArrayObject.html


That's for torque 3d

Not... uh... whatever blockland is on

I'm pretty sure that isn't in this version


DAINGERT.
okay
so i'm making a gamemode where you play several minigames
i need to pick each of them once, and at random, until there are none left in the list
what would be the most efficient way of doing it? i think i could do it if i had arraylists but i don't know if those are in torque either

Use one of the many array implementations (example), choose a random element, do something with it and remove it from the array.

So is the param for onRemove the index or the value?

So is the param for onRemove the index or the value?

What? onRemove is an engine callback for when an object is delete. Look through the comments, every function including the one for removing items is documented.


What the hell. Somehow I forgot to add a function for removing items. Err.


What? onRemove is an engine callback for when an object is delete. Look through the comments, every function including the one for removing items is documented.


What the hell. Somehow I forgot to add a function for removing items. Err.
:I
Do normal arrays have some sort of erase function?


http://forum.blockland.us/index.php?topic=101436.msg1977300#msg1977300
It appears that Truce made arraylists. How would I use these?
Code: [Select]
%aL = new ScriptObject() { class = ArrayList; };
%aL.add("hungry", "hippo");
if(%aL.get(%aL.indexOf("hungry")) !$= "hippo")
    error("the world is broken");
%aL.remove("hippo");
%aL.delete();
« Last Edit: August 11, 2013, 06:05:44 PM by $trinick »

DAINGERT.
okay
so i'm making a gamemode where you play several minigames
i need to pick each of them once, and at random, until there are none left in the list
what would be the most efficient way of doing it? i think i could do it if i had arraylists but i don't know if those are in torque either

this is how I would do it
Code: [Select]
$Mini_Minigame[0] = "Shoe RP";
$Mini_isValid[0] = 1;
$Mini_Minigame[1] = "Baby chainsaw massacre";
$Mini_isValid[1] = 1;
$Mini_Minigame[2] = "Speedkart";
$Mini_isValid[2] = 1;
$Mini_MinigameCount = 2;
$Mini_UsedMinigames = 0;

function selectMinigame()
{
if($Mini_UsedMinigames >= $Mini_MinigameCount)
resetMinigames();

%rnd = getRandom(0,$Mini_MinigameCount);
if(!$Mini_isValid[%rnd])
{
%complete = 0;
%rndOld = %rnd;
for(%i=%rnd;%i<=$Mini_isValid;%i++)
{
if($Mini_isValid[%i])
{
%complete = 1;
%rnd = %i;
break;
}
}
if(!%complete)
{
for(%i=0;%i<%rndOld;%i++)
{
if($Mini_isValid[%i])
{
%complete = 1;
%rnd = %i;
break;
}
}
}
if(!%complete)
{
warn("Error!");
}
}
$Mini_isValid[%rnd] = 0;
$Mini_UsedMinigames++;
$Mini_CurrentMinigame = $Mini_Minigame[%rnd]);
//Do other stuff
}
function resetMinigames()
{
for(%i=0;%i<=$Mini_MinigameCount;%i++)
{
$Mini_isValid[%i] = 1;
}
$Mini_UsedMinigames = 0;
}
« Last Edit: August 12, 2013, 12:22:12 AM by swollow »

http://forum.blockland.us/index.php?topic=101436.msg1977300#msg1977300
It appears that Truce made arraylists. How would I use these?

The post said I never used them at the time, and it turns out I still haven't (lol). But I'm pretty sure when I made it I was looking at a JavaScript source for ArrayLists and just manually ported the code to TorqueScript. Your earlier post asking about ArrayLists implied you knew how to use them, so if I ported it properly back then you should be able to use them just as you are familiar with.

The post said I never used them at the time, and it turns out I still haven't (lol). But I'm pretty sure when I made it I was looking at a JavaScript source for ArrayLists and just manually ported the code to TorqueScript. Your earlier post asking about ArrayLists implied you knew how to use them, so if I ported it properly back then you should be able to use them just as you are familiar with.
Yeah, I'm already familiar with them. Thanks!
this is how I would do it
Code: [Select]
-snap-
I was reading about scriptObjects, and I'm thinking maybe I could have each minigame be a separate ScriptObject. If I did it right, I could make all the minigames very customizable. For example, my code would check the description of the SO Minigame_1 ("dodge the trains" or something) and centerprint it to everyone. Then it would check the position of the minigame's build in the world, and teleport everyone there. Then it would check whether the players should have weapons, whether a few random people are supposed to have weapons, or if one person should be in a vehicle, or several should, and if so, where should they be in that vehicle, etc

or i could just code each one individually

yes script objects would be a better option
don't make everything a separate script object, make a group and add the minigames to it