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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 1531 |
|
|
| 14 Jul 2014 11:14 AM |
| I've fixed it :) Thanks anyway. |
|
|
| Report Abuse |
|
|