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 » Scripting Helpers
Home Search
 

Re: Help with arrays?

Previous Thread :: Next Thread 
ezt12 is not online. ezt12
Joined: 09 Jul 2014
Total Posts: 1531
14 Jul 2014 08:46 AM
I made a script that basically locks all the doors and windows in my place. It used to use a variable for every single door/window in the place and in the lock() method I would have to add a line for every variable (lockdoors(door1/2/3 etc.)), but I was learning about arrays and decided to use that. That way I only have to add a line to the array and it will automatically add it to the lock function.
Here is the new script:

http://pastebin.com/Nt4TKmP3

I'm not exactly sure which part I have done wrong. When I press the button the text on the SurfuceGui changes to "LOCKDOWN ACTIVATED!", but none of the doors lock and the windows don't black out.

(P.S. - I should point out that the script WAS working before I added this.)

Does anyone know what the problem could be?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
14 Jul 2014 08:53 AM
Your best friend with arrays:

for Index, Value in pairs(Array) do
--Stuff
end

So for this, value would be the door that is closing. It is easier to read than while-loops, and I'm not in the mood to look through all those loops ATM, but I hope this helps in the future (Or maybe this is your problem after all, and it will fix it)

Also, another thing, I notice you declare local variables at the top.
Those local variables should be declared in the function they are used in.
Because local variables are so you can use them in a function without messing with other stuff, and from what I heard they are more memory efficient.

So instead of doing

local wt

function blah()
wt = blah2
end

Do this

function blah()
local wt = blah2
end
Report Abuse
ezt12 is not online. ezt12
Joined: 09 Jul 2014
Total Posts: 1531
14 Jul 2014 09:06 AM
I'd prefer something more descriptive. The whole reason I used a while loop is because I can't figure out the for _, i in pairs thing, and the page on the wiki isn't helpful at all.

Would anyone else like to read through the script? The loops really aren't that long... 4 lines if you're lucky.
Report Abuse
ezt12 is not online. ezt12
Joined: 09 Jul 2014
Total Posts: 1531
14 Jul 2014 09:24 AM
Bump. I'll try printing everything and see what comes of that, but in the meantime, could anyone just have a look? ._.
Report Abuse
ezt12 is not online. ezt12
Joined: 09 Jul 2014
Total Posts: 1531
14 Jul 2014 11:14 AM
I've fixed it :) Thanks anyway.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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