Page 12 of 21

Re: Modding Tutorials

Posted: Sat Nov 09, 2019 2:24 pm
by Narf the Mouse
I think I found (part of) the culprit.

The constructors for ModSettings are internal, which means they do not throw an error when you're writing code, but do when the .dfmod gets loaded.

It's not the full culprit because it's not crashing the editor.

Re: Modding Tutorials

Posted: Sat Nov 09, 2019 2:29 pm
by BadLuckBurt
Narf the Mouse wrote: Sat Nov 09, 2019 1:54 pm Thanks for all your help. However, I did "git checkout ." to fix it. It really seemed borked, and I decided to just give up. ;)

Edit: I should clarify. I haven't given up on the mod. :)
No worries, sometimes a reset is the best course of action. And that's the spirit, good luck!

Re: Modding Tutorials

Posted: Sat Nov 09, 2019 2:30 pm
by Narf the Mouse
BadLuckBurt wrote: Sat Nov 09, 2019 2:29 pm
Narf the Mouse wrote: Sat Nov 09, 2019 1:54 pm Thanks for all your help. However, I did "git checkout ." to fix it. It really seemed borked, and I decided to just give up. ;)

Edit: I should clarify. I haven't given up on the mod. :)
No worries, sometimes a reset is the best course of action. And that's the spirit, good luck!
Thanks. It's mostly finished; just needs final polish and an actual settings menu.

Edit: It's mod.GetSettings() now. Also the tutorial needs to be updated. :)

Re: Modding Tutorials

Posted: Sun Nov 10, 2019 9:01 am
by IAmTheClayman
TheLacus wrote: Sat Nov 09, 2019 1:08 pm
IAmTheClayman wrote: Fri Nov 08, 2019 12:44 am How would you go about making changes to an existing script in DFU? For example, right now HUDVitals.cs has the following code:

Code: Select all

public HUDVitals()
            :base()
{
	playerEntity = GameManager.Instance.PlayerEntity;
	LoadAssets();

	BackgroundColor = Color.clear;
	HorizontalAlignment = HorizontalAlignment.Left;
	VerticalAlignment = VerticalAlignment.Bottom;
	SetMargins(Margins.All, borderSize);
	...
I want to, as a test, have the vitals display horizontally centered. Would the way to do this as a distributable mod be to make the edits directly to HUDVitals.cs and include it in the list under Files in the Mod Builder window?
This is not possible (because C# is a compiled language) and also not ideal because two mods that change the same file would be incompatible. See the tutorials on the first page of this topic for some examples of how to make a mod. ;)
I spent some time looking over the examples and digging in the scene hierarchy, but I still can't figure out how to manipulate an existing UI element. It seems that the gameObject DaggerfallUI has a script of the same name, but I can't seem to actually effect a HUD element. For example, I tried the following code this evening:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.UserInterfaceWindows;

namespace ModernVitals
{
    public class ModernHUDVitals : MonoBehaviour
    {
        Mod mod;
        HUDVitals vitals;

        // Use this for initialization
        void Start()
        {
            mod = ModLoader.mod;
            vitals = GameObject.Find("DaggerfallUI").GetComponent<DaggerfallUI>().DaggerfallHUD.HUDVitals;
            vitals.Enabled = false;
            Debug.Log("[[ModernHUDVitals]] Start log hit at " + Time.realtimeSinceStartup);
        }

        // Update is called once per frame
        void Update()
        {

        }
    }
}
However, the vitals are still rendered in-game because the function returns them as a copy rather than a reference. I know the code is at least being because the Debug.Log is printing. But because the methods DaggerfallUI.DaggerfallHUD and DaggerfallHUD.HUDVitals have getters only and no setters I can't see any way to alter the way the HUDVitals are displayed, not unless I decativate the standard UI script and write a custom replacement for DaggerfallUI. Is there something obvious I'm missing here that would allow for a simpler solution?

Re: Modding Tutorials

Posted: Thu Feb 27, 2020 7:34 pm
by Hazelnut
LypyL wrote: Sat Jun 18, 2016 7:52 am Known Issues

enums - scripts with enum types defined will fail to compile. You can still use any of the enum types already in the project. This is an issue with the mcs compiler.

generic functions / classes - similar to the above, due to an issue with the compiler scripts that try to define generic functions will not compile.

Unity Versions - mods created in newer versions of unity might not be compatible with older versions of unity. This is noticeable if the mod is in the mod directory, but doesn't show up in the list of mods.
I think I've found another restriction of the mcs compiler, as code works in editor but not when packed in a .dfmod and this was the issue that Meaner Monsters mod ran into. It seems that you cannot use c# object initialisation with structs, works fine with classes though.

Re: Modding Tutorials

Posted: Tue May 05, 2020 9:18 pm
by l3lessed
Yes, the documentation for setting up mod settings needs updated badly. It is completely misleading. The forum post is outdated, the web page isn't complete in its documentation.

I'm using the build in mod setting creator, opening it up and saving it within the same folder as the mod script file, and I am then loading mod.GetSettings(); with awake, start, and Init. Still, no settings are showing up in the mod.

I also added the json file as an asset within the mod builder to ensure it compiles with the mod. I'm trying to track down mods to back engineer to see how it is done, but can someone provide updated documentation on this area?

Re: Modding Tutorials

Posted: Tue May 05, 2020 9:36 pm
by Ralzar
Like, the mod settings that you can adjust in the mod list? All you need is to list the "modsettings.json" in the *.dfmod.json file.

Take a look at my Level UpAdjuster. It uses a LOT of mod settings,

LevelUp Adjuster

Re: Modding Tutorials

Posted: Tue May 05, 2020 9:59 pm
by l3lessed
I got it. It was something small like I thought, but it should still be listed on the webpage.

I did not realize the modsettings was a separate namespace from the modsupport namespace. I would think it would be part of the general modsupport namespace, as it would logically seem to be part of mod support. Bad assumption.

Also, you can just add the settings file as an asset to the mod builder window to get it into the mod json without having to manually go into and add it yourself using a text editor.

These two documentation additions would take five minutes to add to the top of the mod settings documentation page, so future modders know right upfront modsettings is its own namespace. I know, rookie mistake, but that is what good documentation is supposed to be for.

Thanks, as always everyone, for sharing your work, so I can trouble shoot these things.

Re: Modding Tutorials

Posted: Tue May 05, 2020 10:08 pm
by TheLacus
The documentation on the website looks complete to me, what would you suggest to add?

I'm going to edit the forum post with obsolete tutorial so it won't confuse anymore in the future. ;)

Re: Modding Tutorials

Posted: Tue May 05, 2020 10:37 pm
by l3lessed
It's a small nitpick thing, but I don't see any reference to using the differing namespace to access the modsettings. I thought it was built into the modsupport name space. Maybe I overlooked this somewhere? If not, it would of helped for me to see the modsettings namespace setup. Specifically, this below.

using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings;

Did I overlook it, or is this such a basic part of Object Orientated coding that no one feels it is needed clearly stated. It was a pretty rookie overlook.