Any of array's variables?

About advanced scenes, and the Thyme scripting language used in Algodoo.

Any of array's variables?

Postby lololoer16_17 » Sat Feb 08, 2014 5:51 pm

I want to make a function, to read if anything of the integers of an array are true/false/etc..

I have tried:

_Array=[fase,false,false,true,false];
scene.my.AnyOf= (array, variable)=>{
for(string.length(array),(i)=>{array(i)==variabe})?"there's something equal":"there isn't anything equal"
}
scene.my.AnyOf(_Array,true);

But it does not work, it gives me an error.

Thanks.
lololoer16_17
 
Posts: 18
Joined: Tue Jan 21, 2014 8:55 pm
Location: Spain (South)

Re: Any of array's variables?

Postby Xray » Sun Feb 09, 2014 8:09 am

That's easy!

Define your array in the console: scene.my.array := {[true,true,false,false,true,true]}

Test each array element for true or false: scene.my.array(n) ? {Do this if true}:{Do this if false}

where, n is the array element beginning with 0 (zero).

Is this what you needed?
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Any of array's variables?

Postby lololoer16_17 » Sun Feb 09, 2014 5:11 pm

No, Xray, I mean:
array= [false,true,false,false,true,true];
is there anything true on the array list?{do something}:{do something};

I don't mean to ask for an specific element, I want to ask if there's any element true on the array.
lololoer16_17
 
Posts: 18
Joined: Tue Jan 21, 2014 8:55 pm
Location: Spain (South)

Re: Any of array's variables?

Postby s_noonan » Sun Feb 09, 2014 6:13 pm

Code: Select all
Scene.my.xFor := (n1, n2, code)=>{
    n2 > n1 ? {
        m := (n1 + n2) / 2;
        scene.my.xFor(n1, m, code);
        scene.my.xFor(m + 1, n2, code)
    } : {code(n1)}
};

scene.my.isAnyTrue = (ra)=>{
    v = false;
    n = string.length(ra) - 1;
    Scene.my.xFor(0, n, (i)=>{
        ra(i) ? {v = true} : {}
    });
    v
}

scene.my.ra = [false,false,true,false];
scene.my.isAnyTrue(scene.my.ra);

scene.my.ra = [false,false,false,false];
scene.my.isAnyTrue(scene.my.ra);


scene.my.xFor is from Kilinich and has no limit to the number of iterations.
s_noonan
 
Posts: 61
Joined: Tue Mar 30, 2010 2:25 am

Re: Any of array's variables?

Postby lololoer16_17 » Sun Feb 09, 2014 7:40 pm

Thanks s_noonan :clap: :clap:
lololoer16_17
 
Posts: 18
Joined: Tue Jan 21, 2014 8:55 pm
Location: Spain (South)

Re: Any of array's variables?

Postby Xray » Sun Feb 09, 2014 7:43 pm

He's GOOD! :thumbup:
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests