Computer Science Canada Simple loop problem |
Author: | x-ecutioner [ Mon Nov 24, 2008 4:44 pm ] | ||
Post subject: | Simple loop problem | ||
hi im trying to get my square to move from the left side to the ride side of the screen and back. the issue is, it gets to the right side and gets jammed there. i know its a simple problem but i just cant figure it out
any ideas? thanks for any help possible |
Author: | Insectoid [ Mon Nov 24, 2008 4:54 pm ] |
Post subject: | RE:Simple loop problem |
Think about it. The box is at 50. It is as 50. It adds moves right until it becomes greater than 450. It is then moved left by ten, at which point it is less than 450, so it moves right again. Hope I helped! |
Author: | x-ecutioner [ Mon Nov 24, 2008 5:10 pm ] |
Post subject: | RE:Simple loop problem |
it definetely helped but the question remains how do i make it go bcak to the direction it came from im not looking for actual code but perhaps a suggestion on what should probably be changed :S argh its such a simple problem i gotta sleep more lol |
Author: | x-ecutioner [ Mon Nov 24, 2008 5:12 pm ] |
Post subject: | RE:Simple loop problem |
actually dont worry about thank you very much for your help:) i decided to use for loops instead. |
Author: | copthesaint [ Mon Nov 24, 2008 5:30 pm ] | ||
Post subject: | Re: Simple loop problem | ||
Well If you look at the code
You see that once inc will equal 450 it will continueously go back from 440 to 450. Also if you want to do this right add a cls after the last View.Update. and delet the the white box you keep creating. Furthermore, if you want a smoother running program then shorten the delay to 3 and decrease inc:= inc-10 to inc-= 1 as you see also I changed the := to -= It does the same thing to the effect you were wanting but less typing. |
Author: | Insectoid [ Mon Nov 24, 2008 5:40 pm ] | ||
Post subject: | RE:Simple loop problem | ||
instead of using for loops, use a variable to hold the movement.
this can be shortened using the 'or' operator, I just showed the expanded version so you would know what was going on. So the box has 1 added to it, then it hits a wall. The move is flipped to negative 1. adding negative 1 is the same as subtracting positive 1, so it moves the other way. |