Retruvius
|
  |
| Joined: 26 Aug 2010 |
| Total Posts: 1493 |
|
|
| 21 Apr 2015 01:05 PM |
I see that it isn't i++
What I have:
Brick= script.Parent
while true do for i = 1, 3 do Brick.CFrame = Brick.CFrame + Vector3.new(4,0,0) wait(0.5) i= i+1 end if i == 4 then Brick.CFrame = Vector3.new(0,0,0) i = 1 end end
I want it to increment until it gets to 4 at which point it skips the for, goes to the if, where its position is reset to the original one, and i is set back to 1 |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2015 01:08 PM |
the for statement automatically stops when it reaches the second parameter, the 3. simply change the three and put Brick.CFrame = Vector3.new(0,0,0) right before the end for the while loop. Alternatively you can get fancy and use the third parameter of the for loop.
while true do for i = 0,12,4 do wait() Brick.CFrame = CFrame.new(i,0,0) end end |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2015 01:11 PM |
Euhm, 'i' in a for loop (also replacements for 'i') will automaticly add 1 every loop, so you don't have to do that.
Also, 'i' goes from 1 to 3, so it can never be 4
And last, 'i' is a local string, not a global. You can't use the 'i' again in the if statement because the 'i' string is only readable by if's [in] the for loop. |
|
|
| Report Abuse |
|
|
Retruvius
|
  |
| Joined: 26 Aug 2010 |
| Total Posts: 1493 |
|
|
| 21 Apr 2015 01:32 PM |
I got it to work so that it moves 4 studs at a time every .5 seconds, but I can't get it to reset to its original position :/
Thanks for the help so far, not sure I understand the first answer cause it's not working |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2015 01:37 PM |
"Euhm, 'i' in a for loop (also replacements for 'i') will automaticly add 1 every loop, so you don't have to do that.
Also, 'i' goes from 1 to 3, so it can never be 4
And last, 'i' is a local string, not a global. You can't use the 'i' again in the if statement because the 'i' string is only readable by if's [in] the for loop."
it is not "i" or "replacements for i", it is a variable typically declared as i.
the i does not add 1 every for loop. in lua, it defaults to 1. you can specify (as with all other languages) any other number.
and i is not a string, and it is not "readable by if's". it is a variable. |
|
|
| Report Abuse |
|
|