Page 1 of 1

Script Problem

Posted: July 14th, 2007, 5:43 am
by dizzy
I know for sure this is not the right script...

But do you think you could clairify for me how to do arrays?

Code: Select all

main()
{
thread run();
}
run()
{
trig = getent ("trig","targetname");
step = getentarray ("step","targetname");
{
trig waittill ("trigger", user);
user iprintln ("HI");
step[0] moveto (200,32,248,1);
step[1] moveto (200,32,248,.9375);
step[2] moveto (200,32,248,.875);
step[3] moveto (200,32,248,.8125);
step[4] moveto (200,32,248,.75);
step[5] moveto (200,32,248,.6875);
step[6] moveto (200,32,248,.625);
step[7] moveto (200,32,248,.5625);
step[8] moveto (200,32,248,.5);
step[9] moveto (200,32,248,.4375);
step[10] moveto (200,32,248,.375);
step[11] moveto (200,32,248,.3125);
step[12] moveto (200,32,248,.25);
step[13] moveto (200,32,248,.1825);
step[14] moveto (200,32,248,.125);
step[15] moveto (200,32,248,.0625);
user iprintln ("HI");   
}
}

Posted: July 14th, 2007, 1:48 pm
by Drofder2004
the main way of using arrays is combining them with for loops which basically tell the entire array to repeat the same action for every part of the array...

you script has a changing deceleration so it makes it slightly harder, your pattern is currently irregular making this slightly harder but can still be done.

Through the use of some maths and code, hopefully this should work.

Code: Select all

pattern = ((1 - 0.625) / array.size;
j=undefined;
for(i=0;i<array.size;i++)
{
j = 1 - (pattern * i);
iprintln(j); //Debug
array[i] moveto (200, 32, 248, j);
}
So your full code is...

Code: Select all

main()
{
thread run();
}
run()
{
trig = getent ("trig","targetname");
step = getentarray ("step","targetname");
pattern = ((1 - 0.625) / step.size);
j=undefined;
while(1)
{
trig waittill ("trigger", user);
user iprintln ("Start"); // Debug

for(i=0;i<step.size;i++)
{
j = 1 - (pattern * i);
iprintln(j); // Debug
step[i] moveto (200, 32, 248, j);
}
user iprintln ("End");   // Debug
}
}
I corrected a mistake where you did not put the 'while' function. You cannot open { brackets for no reason, they must be along side a function that allows them, such as 'while', 'for', 'if' and when you open a function (main() {})