0 votes

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

in Engine by (71 points)

2 Answers

+4 votes
Best answer

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

by (1,204 points)
selected by

thanks so much

–1 vote

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

by (196 points)

That would be correct for "return", but isn't for "pass".

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.