Damned Arrays
I've been trying since yesterday to figure out what I'm doing wrong. I try to initialize a multidimentional array in a method inside a class and then fill it using a double for loop. Trying to fill it all with # characters. I know if I take out the word public it seems to have less errors but then I can't access it outside of the method. I assume I could pass it out as a return but I was hoping I could just access it directly for now. With the public word in front it gives me a whole bunch of errors. I assume I have the syntax wrong somewhere or I'm doing something I can't do inside of a method but don't know why.
10 Replies
public
and other accessibility modifiers like private and internal are not valid on local variables
only on classes, fields, methods, properties
you need to either return the array from BuildMaze, or move it to a field or property on the class @drewhosickYou won't be access it ourside of the method either way
They're called "local variables" for a reason
$structure
If you want the array to be available to other methods in the class, you will need to move it to the class scope
$scopes
thing a
is available in scope A
and scope B
thing b
is available only in scope B
personally I'd change this to
ah crap eh. Ok thanks
I knew it couldn't be hard but I just couldn't figure out what I was doing wrong. I just moved the declaration outside the method and it works now. Thank you for the quick lesson on scope. I didn't know you couldn't create a public variable in the method that would be available outside by using the public modifier.
$close
Use the /close command to mark a forum thread as answered