Fumetsu
✅ Good way to access methods from other classes?
I mean, I found a work around by having the Spark class send the command to the Command class instead of the MainForm, since the Spark class is the one that instantiates all of the classes anyways. Not exactly how I'd prefer it but it works. Sorry for being hard to work it, I'm abit out of my depth and I should definetely go out of my way to learn abit more. Thanks for all of the information you provided though! I'm sure it will prove rather useful
17 replies
✅ Good way to access methods from other classes?
Okay so, every class is under the same namespace, which allows them to use this class that specifies all the instanced classes, so all classes access the same classes without instancing new ones
I currently have the MainForm under a different namespace, as for some reason putting it in the same namespace as my other classes breaks my code, idk why exactly maybe I need to look into it sometime. This class is under the MainForm namespace to give the MainForm access to all the classes, but this instances the other classes again. Now don't get me wrong I am way out of my depth here so idrk what I'm talking about, but I believe this means that the classes that the MainForm and other classes access are basically different classes. When my app loads I typically have the Spark class handle everything, which has worked fine, one thing it did is load a bunch of commands from the Command class into a list. If I have any other class run the RunCommand method from my Command class it works perfectly fine (RunCommand only runs code if the provided command is found in the commandList) but when the RunCommand method is accessed from the MainForm, it doesn't work. I used a foreach loop to print the values of the commandList in the Commands class, and if ran from any other class it prints all the commands I added, but if ran from the MainForm it prints nothing, as if no commands were added
17 replies
✅ Good way to access methods from other classes?
Maybe I'm misunderstanding, but to access methods/variables from another file I have to instance it, which is typically done by using something like
classFile specifiedName = new classFile();
right? This has worked for me until I've needed the MainForm to access a specific method. I have a method in my Command class file that runs a command, if said command is found in a list, which commands are added to when the application starts. Problem is, since MainForm creates a new instance of the class file, I believe that Command list is never built, so the command never runs. I've tried running commands from every other class file and it works, but only from the MainForm does running the command never work, I'll show my code abit more in a sec17 replies