generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Increment in lua?

Previous Thread :: Next Thread 
Retruvius is not online. 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
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
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
SeizureMadness is not online. SeizureMadness
Joined: 23 Apr 2011
Total Posts: 154
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 is not online. 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
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image