How to remove item from array
How to remove current item from array in this case ?
for al in al1
if al.y<100 then al.REMOVE? end
end
How to remove current item from array in this case ?
for al in al1
if al.y<100 then al.REMOVE? end
end
read the documentation:https://microstudio.dev/documentation/microScript-cheatsheet/ list.removeAt( index ): Removes from the list the element at position index list.removeElement( element ): Removes from the list element, if it can be found in the list
it found, but nothing removed, uses both of it functions:
init = function()
z=["231","31e","qwe1"]
for i in z
// print (i)
if i=="31e" then
print("Delete: "+i)
z.removeAt[i]
z.removeElement[i]
end
end
for i in z
print (i)
end
end
update = function()
end
draw = function()
end
result is:
microScript 2.0
Delete: 31e
231
31e
qwe1
// Method 1
z=["231","31e","qwe1"]
z.removeElement("31e")
print(z)
// Method 2
z=["231","31e","qwe1"]
for i=0 to z.length-1
if z[i]=="31e" then z.removeAt(i) end
end
print(z)
// Method 3
z=["231","31e","qwe1"]
pos=z.indexOf("31e")
if pos>=0 then z.removeAt(pos) end
print(z)
end
but if
z=[
object x=1 y=2 end,
object x=2 y=3 end,
object x=3 y=1 end
]
Example in how to remove an object, where y==300
z=[
object x=1 y=200 end,
object x=2 y=300 end,
object x=3 y=100 end
]
for obj in z
if obj.y==300 then z.removeElement(obj) end
end
for obj in z
print(obj.x+","+obj.y)
end