a proplem with "for"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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):
print("the array do is: ", do)
print("the array in do is: ", in_do)
   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.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

i have no errors but the line


does not execut that mean that the func for does not work
pleas help me i am stoked
this is the project : https://drive.google.com/open?id=1OFCpBa0q9yCzWlYa9fELje-xnOVyVyze

:bust_in_silhouette: Reply From: rustyStriker

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

thanks so much

abdolilah | 2020-03-05 20:02

:bust_in_silhouette: Reply From: newold

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”.

njamster | 2020-03-06 15:03