Check if a variable is in an array

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

Check if a variable is in an array

Postby HQTG1 » Mon Jul 10, 2017 11:00 pm

Is there a built-in function that simply checks if a value is in an array and returns a boolean? I've looked at all of the Thyme tutorials I could find and I've checked the massive list of Thyme commands & variables sticky. All I want to do is this:
Code: Select all
array0 = [1, 2, 3]

var0 = 1

    <check if var0 is in array0> ? {
        doAThingIfVar0IsInArray0()
    } : {
        DoAThingIfVar0IsNotInArray0()
    }


Looking at the lack of support for everything else (we don't even have loop structures), I won't be surprised if there isn't an easy way of doing this.
User avatar
HQTG1
 
Posts: 2
Joined: Thu Nov 03, 2016 5:12 am

Re: Check if a variable is in an array

Postby Luezma » Wed Aug 30, 2017 7:57 am

If you want to check if an element of array0 is equal to var0 and you know how many elements does array0 has (0 being the first element), then:
Code: Select all
for(array0lenght, (i)=>{
    array0(i) == var0 ? {doSomeStuff()} : {dance()}
})
Luezma
 
Posts: 14
Joined: Thu Dec 13, 2012 7:19 pm
Location: Argentina


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron