This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Christie Gettler Tarazon
Posted Mar 01 - Read on Facebook

Hi all, maybe a pretty basic question here, I'm not sure, but I need some help with arrays.
I have a list of numbers (let's call it the "readout") that are related to another list of numbers (let's call it the "value"). For instance, if the readout is equal to 5, the value is 23. I need to set a variable equal to the changing value as the readout changes. So, if readout==5, myVar=23.
In an effort to not write a huge if/else if statement, I feel like arrays could help me but I'm not sure how to write it...

4 Comments

Christie Gettler Tarazon

something along the lines of this? :

readout = ["5", "6", "7", "8"]
value = [23, 28, 35, 42]

myVar = 0

# there is a text layer that can be any of the values in the "readout" array

if textLayer.text == readout[???]
myVar = value[corresponding index to the readout index]

Christie Gettler Tarazon

could indexOf work? or maybe can Utils.modulate run through 2 arrays rather than 2 sets of values?

Christie Gettler Tarazon

i think I've solved it. will update in a few.

Christie Gettler Tarazon

okay so here's the method:

# arrays ////////////////////
readout = ["5", "6", "7", "8"]
value = [23, 28, 35, 42]

# variables //////////////////
# using .indexOf, compareVar will search the readout array to see if the textLayer text matches any of the strings in the array; if it does, it will return the index position of that string
# myVar then gets the corresponding number out of the value array by pulling the number from the same index position

compareVar = readout.indexOf(textLayer.text)
myVar = value[compareVar]

# in numbers: ////////////////////////////////////////

textLayer.text = 6
compareVar = read.indexOf(6) # returns 2
myVar = value[2] # returns 28

Read the entire post on Facebook