Hi Jonathan,
You don’t have to. The use of the parameters will be determined by what the method needs to do.
The name input
is not mandatory, it can be called whatever you want, just as when you declare a variable. However, in Terminal Hacker the text values that you pass around from method to method are typically based on the player’s input, so the name kinda makes sense.
A member variable, e.g. one declare within the class but outside of any methods will have a different scope to that of the parameters you define in your methods. Anything set in the member variable would be accessible to all methods, and, as you’ve stated, you’d only have to declare it the once. However, you would need to then also change all of the methods to look at that specific member variable as opposed to using the parameters that are currently being passed in.
Taking this a step further, the way that the code for the WM2000 currently works (not sure if you’ve had a look) is to use reflection to find all of the methods within the entire solution that have a specific name (OnUserInput from memory) and then invoke them, passing the player’s input as a parameter. This is how this method within your own Hacker.cs script gets executed each time there is a change in input received from the player.
I suppose you could use the OnUserInput
method as-is, but then set the member variable from this method, which your other methods would look at. One of the risks I would suggest however is being 100% certain that the value that is now in the member variable (at any given time) was the value you were expecting and that it hasn’t been updated/changed since you started working with it. Where-as at the moment each subsequent method call is handed the value to use explicitly.
Hope this helps