Zorkaz Posted February 25, 2020 Posted February 25, 2020 The setup:I have a menu with different options (Opened from an activator)Choosing an option will lead to another submenu with further options The issueI want the submenus to be separated from the main menu. This also means the submenus should have a unique script. (This is because I want to create a framework (.esl) and want other modders not to meddle with the mods main menu) Any ideas on how to access a submenu with it's own scripts?My current take is to enable/disable a trigger that opens the submenu but it sounds so messy when dealing with 25 submenus
niston Posted February 25, 2020 Posted February 25, 2020 I do this a lot, as I like a clean design that separates concerns. In my EEE mod for example, I have a script for the basic "maintenance" menu, and then dedicated scripts for each of the options from the maintenance menu. You can do this by attaching multiple scripts to a single object and then cast Self as any of the Script types that are attached. This lets you access, from one script, functions and properties on the other scripts: ((Self as ObjectReference) as Your:OtherScript).FunctionOnOtherScript(parameter1, parameter2, ...) The intermediate cast to ObjectReference is necessary to access the other script types, as "Self" will be of the calling script's own type. It's also a good idea to test if the cast resulted in none, in case you forgot to attach one of the submenu scripts: Your:OtherScript myOtherScript = ((Self as ObjectReference) as Your:OtherScript)If (myOtherScript == none) Debug.Trace(Self + ": ERROR - myOtherScript is none!")Else myOtherScript.ShowOtherSubMenu()EndIf I further have conditions for my maintenance menu buttons, so I can hide the options for which no scripts are attached (not all options make sense for all the objects).Btw: F4MS has a facility to support these conditionals. And another facility for text replacement in message boxes (so you don't go crazy each time you have to make a messagebox menu). Last but not least: If you want to make a "framework" style thing, I suggest you use inheritance. Create a base class that defines a submenu's interface. You (and other modders) can then derive submenus from that base class. The main menu can then always rely on the methods and properties of the base class being present on any of the submenu scripts. It can thus handle any existing (present and future) derivate you or anybody else might come up with, without knowing about them specifically. Added benefit: Code that's common among all submenus can also go into the base class, so it'll only have to be written -and maintained!- once. I can send you my EEE mod scripts if you want to take a look. Everything I described here is used extensively by them. F4MS also uses the "multiple scripts attached" technique for the factory control panel script, which is completely separate from the factory script itself.
Recommended Posts