Topic was automatically imported from the old Question2Answer platform.
Asked By
abdolilah
i am working on a small project tat manages your tasks
and i have a problem
so i coded a script that give the bars wish position they should be at
var in_do=[]
func plus_in_do(node_number):
in_do.append(node_number)
print("the array do is: ", do)
print("the array in do is: ", in_do)
pass
for x in in_do.size():
if $bars.get_child(x).get_child(0).node_statu==0 :
$bars.get_child(x).get_child(0).rect_position.x=$Position2D.global_position.x
$bars.get_child(x).get_child(0).rect_position.y=$Position2D.global_position.y + in_do[in_do.find($bars.get_child(x).get_child(0).node_number)] * 8 + in_do[in_do.find($bars.get_child(x).get_child(0).node_number)] * 80
print("ok")
pass
So, for loop is like foreach in more strong type languages, in your case you take a number and iterate through it(which doesnt work fyi), if you want to iterate all the way up to the size of the array like for(int i = 0; i < Array.size(); i++) you will need to do for i in range(Array.size()).
if you want to iterate with an iteration variable a fixed number of times you need to use the range keyword.
the range keyword can be used with up to 3 parameters: range(x) - from 0 to x ( excluding x ) range(y,x) - from y to x ( including y, excluding x ) range(y,x,z) - from y to x, raising the iteration by z
(for example range(1,10,2) will result in [1, 3, 5, 7, 9]
Hope it helps you or any other gal stumbling across this, and have a nice day
you have the “pass” command below the line you “print (" the array in do is: ", in_do)”, then, this function only works up to that line and for x in in_do.size(): … is not executed
That would be correct for “return”, but isn’t for “pass”.