How to change elements of a list by using a command?

Jelle Torres shared this question 3 years ago
Answered

I have a list L = {0,0,0,0}


when i press a button i like to change the first 0 in to a 1


i did try


SetValue[L(1), 1]

and

L(1) == 1


but this doesn't seem to work. Does anyone have a clue how i can fix this?

Comments (3)

photo
1

Please try SetValue[L,1,1] to change first element, SetValue[L,5,1] to add element on fifth position.

photo
1

Thank you that works perfectly

photo
1

If I have a long list of booleans eg listBool = {a, b, c,,,,z}

where a, b, c are currently false, and I want to change, the 3rd element, c to be true, ie c = true using count = 3,

this won't work in Geogebra script.

  1. count = 3 #count from input or other computation
  2. SetValue[listBool,count,1] #set the 3rd element in listBool to true, where listBool are boolean objects


Help is appreciated. Otherwise I have to do one by one, for example.

  1. SetValue[b, If[count == 2,true,false]
  2. SetValue[c, If[count == 3,true,false]

© 2020 International GeoGebra Institute