Author Topic: Auto Falling Plates code not making plates fall.  (Read 2251 times)

I am trying to make a Falling Plates similar to DAProg's. put the PlatesFall function is broken.
Code: [Select]
function PlatesFall(%id)
{
ColorMessage(%id);
%groupCount = MainBrickGroup.getCount();
for(%i = 0; %i < %groupCount; %i++)
{
%brick = MainBrickGroup.getObject(%i);
%dataname = %brick.GetDataBlock().GetName();
%color = %birck.GetColorID();
if(%dataname $= brickFallingPlateBaseData && %color == %id)
{
%brick.schedule(3000,"Fall");
}
if(%dataname $= bricklight1x1BaseData || %dataname $= bricklight1x2BaseData)
{
%brick.SetColor(%id);
}
}
}

"Fall" is an event I made for the plates. The brick1x1/1x2lightbaseData and brickFallingPlateBaseData are custom bricks. ColorMessage works fine.

I can understand that you can have problems at programming logic, but you appear to have issues with your overall logic too. Did you even look through the code before posting?

I think it's funny how he can't even spell brick

I think it's funny how he can't even spell brick
simple mistakes dude

You have a couple of syntax errors and large holes in your logic.

Name the plate Plate-red
Then
Put
_PlateDASHred.fireinputevent("fall");
in script
Or am I wrong

Name the plate Plate-red
Then
Put
_PlateDASHred.fireinputevent("fall");
in script
Or am I wrong

does DASH represent _ ?

why not just put _Plate_red.fireinputevent("fall");?


Code: [Select]
%brick = MainBrickGroup.getObject(%i);
i feel like %brick is a brickgroup, not an actual brick
do another for loop similar to the first, to be more like
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
    for(%b = 0; %b < MainBrickGroup.getObject(%a).getCount(); %b++)
    {
         %brick = MainBrickGroup.getObject(%a).getObject(%b);
    }
}

does DASH represent _ ?

why not just put _Plate_red.fireinputevent("fall");?
DASH represents a -
Plate-red would be PlateDASHred
Plate_red would be Plate_red

Code: [Select]
%brick = MainBrickGroup.getObject(%i);
i feel like %brick is a brickgroup, not an actual brick
do another for loop similar to the first, to be more like
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
    for(%b = 0; %b < MainBrickGroup.getObject(%a).getCount(); %b++)
    {
         %brick = MainBrickGroup.getObject(%a).getObject(%b);
    }
}
No

Or?

No

Or?

What?



Code: [Select]
%brick = MainBrickGroup.getObject(%i);
i feel like %brick is a brickgroup, not an actual brick
do another for loop similar to the first, to be more like
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
    for(%b = 0; %b < MainBrickGroup.getObject(%a).getCount(); %b++)
    {
         %brick = MainBrickGroup.getObject(%a).getObject(%b);
    }
}

Please learn to optimize your code. For every group of bricks, you're calling mainBrickGroup.getCount() and for every single brick, you're calling mainBrickGroup.getObject(index) twice and mainBrickGroup.getObject(index).getCount().

Code: [Select]
%group_count = mainBrickGroup.getCount();

for ( %i = 0 ; %i < %group_count ; %i++ )
{
%group = mainBrickGroup.getObject( %i );
%brick_count = %group.getCount();

for ( %j = 0 ; %j < %brick_count ; %j++ )
{
%brick = %group.getObject( %j );
}
}

Please learn to optimize your code. For every group of bricks, you're calling mainBrickGroup.getCount() and for every single brick, you're calling mainBrickGroup.getObject(index) twice and mainBrickGroup.getObject(index).getCount().

Code: [Select]
%group_count = mainBrickGroup.getCount();

for ( %i = 0 ; %i < %group_count ; %i++ )
{
%group = mainBrickGroup.getObject( %i );
%brick_count = %group.getCount();

for ( %j = 0 ; %j < %brick_count ; %j++ )
{
%brick = %group.getObject( %j );
}
}
just saying an example, and in other programming languages it's done automaticaly, probably not in torquescript though
there's no reason to tell others to optimize their code for posting a basic example which is easy to read

there's no reason to tell others to optimize their code for posting a basic example which is easy to read

...Yes there is...

...Yes there is...
optomized code is better for released addons, while if you're helping somebody learn something like this, it's easier to read the way i posted it
so, no there isn't