Jump to content

Adding Properties to an Object and Interacting with the MCM


Recommended Posts

Hello Fellow Modders,

 

Big Picture: I have a lot of doors in my basement (connecting to player homes) and depending on what the user selects (through the MCM) for the status of each door

 

  • Is It In Game (.i.e "No way do I want a door in my basement leading to the Dark Brotherhood Sanctuary, creepy" :ohmy: )
  • Is It known by the player (i.e. "Have I ever been in the Dark Brotherhood Sanctuary? Yes but its not what you think. I was going door to door selling cookies and I asked to use their restroom..." :sick: )
  • Is it On the Network to fast travel between places (i.e. "I like having access to my basement from the Dark Brotherhood Sanctuary, but I don't want them to follow me into my nice home, so it is off network" :ermm: )
  • Which is the current Active Door ("Are you asking if I entered my basement just now from the Dark Brotherhood Sanctuary? Well, I could tell you but then... :devil: ")

 

I want to update which doors are Enabled.

 

I have a working version with the InGame and IsKnown. I am using global variables for each door and each status. While it works, it seems to be the wrong approach.

I have started adding the OnNetwork, and the Event OnOptionSelect is starting to get ugly.

 

Ugly code warning! You don't need to read this. This MCM is not complete and the Indentations did not transfer??

 

  Reveal hidden contents

 

 

 

So, I am thinking that using Global Variables is not ideal.

 

It seems to me that it would be better if I could just add four properties to a base door, lets call it MyDoor

MyDoor.IsKnown

MyDoor.IsInGame

MyDoor.IsOnNetwork

MyDoor.Index

Scriptname dw01_MLB_Door extends ObjectReference  
;||||||||||||||||||||||| 1=TRUE     0=FALSE |||||||||||||||||||||||
Int Property Index Auto ;Used to track which door is the Active Door
Int Property IsInGame Auto ;User decides if door is available in game
Int Property IsKnown Auto ;Has Player Used the door yet
Int Property IsOnNetwork Auto ;Does door into MLB allow other exit options through other doors

Then I use this door as the Parent, and make 11 Child copies

MyDoor00 ... MyDoor11

And they all have the properties.

 

 

I can then add these doors to a FormList and loop through the list getting the properties (IsInGame, IsKnown, IsOnNetwork) on that door to decide if the door should be enabled.

 

Is this how I should be doing this?

 

Will I still need to use one global for each door and each of the properties to interact with the MCM?

 

I appreciate any advice.

 

Have a great day!

Edited by tamtastic
Link to comment
Share on other sites

If you are putting the doors into a formlist, you just need the formlist property. Everything else can be referenced in arrays for the MCM to work with

FormList Property DoorList Auto
dw01_MLB_Door DoorScript
Int[] DoorIndex
;do the same with the others
 
Event OnConfigInit()
  DoorIndex = new Int[12]
  ;do the same with the others
 
  ;Then you can get the starting property values from each by doing the following:
  Int idx = 0
  While idx < DoorList.GetSize()
    DoorScript = (DoorList.GetAt(idx) as ObjectReference) as dw01_MLB_Door
    DoorIndex[idx] = DoorScript.Index
 
    ;do the same with the others 
 
    idx += 1
  EndWhile
EndEvent

For the option selections you can change the array value as needed.

 

To actually change the values of properties on the various doors

Event OnConfigClose()
  RegisterForSingleUpdate(0.1)
EndEvent
 
Event OnUpdate()

  Int idx = 0
  While idx < DoorList.GetSize()
    DoorScript = (DoorList.GetAt(idx) as ObjectReference) as dw01_MLB_Door
    DoorScript.Index = DoorIndex[idx]
 
    ;do the same with the others 
 
    idx += 1
  EndWhile
EndEvent
Link to comment
Share on other sites

Forgot to include that if you want / need to force the OnConfigInit event to run again after the mod has already been active you can do that with a bit of "versioning"

Int function GetVersion()
	return 2 ; Default version
endFunction

Event OnVersionUpdate(int version)
	If version > 1
		OnConfigInit()
	EndIf
EndEvent
Link to comment
Share on other sites

Wow. IsharaMeradin I truly appreciate your help. I have it working using formlists and arrays! Now I just have 40+ global variables I can release back into the wilds of Skyrim. Global Variables (Globs) will never again tremble in my presence.

 

Your post is a coding lesson in itself. I am going to make sure I understand every part of it. The biggest help was demonstrating how to actually attach and use a Script (DoorScript). I am so elated to finally understand this.

 

I posted the whole code (even though it is still not a finished MCM) incase anybody else is struggling with using arrays and formlists. Yes, there are still some gratitous global variables, sorry Globs looks like you are not completely safe after all. One other thing I learned, this forum editor does not like Tabs for indentation, so I did a mass convert of Tabs to spaces (Thanks Notepad++).

 

 

Thank you again IsharaMeradin!

 

  Reveal hidden contents

 

Edited by tamtastic
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...