Jump to content

Recommended Posts

Hello fellow modders!

 

 

So I am creating my first character mod atm and I am done with the art-part. Now I want a custom bar that shows a variable value. Just like hunger, health or sanity. I already did a working bar mostly through following this thread. So to save you from reading the whole thing I basically copied the health.lua component, renamed it and put it in /scripts/components. Then I added the line

inst:AddComponent("shadowcounter")

to local master_postinit. The next step would be to change the bars position since it is overlaying the health bar. The code to do this is:

ShadowWidget = Class(GLOBAL.Widget, function(self, owner)    	GLOBAL.Widget._ctor(self, "ShadowWidget")    	self.owner = owner    	self.base_scale = .5    	self:SetScale(self.base_scale,self.base_scale,self.base_scale)    	self:SetPosition(100,20,0)    	self.text = self:AddChild(GLOBAL.Text(GLOBAL.NUMBERFONT, 40/self.base_scale))    	self.text:SetString("Test Widget Works!")end)local function initMod()    	local player = GLOBAL.GetPlayer()    	if player ~= nil and player.HUD ~= nil 	then        		player.HUD:AddChild(ShadowWidget(player.HUD.owner))    		endendAddSimPostInit(initMod))

I put that in scripts/widgets. Now the problem starts. I am adressing it by adding the following line at the start of my characters /scripts/prefab/character.lua. 

require "Scripts/Widgets/shadowwidget.lua"

When starting the game while the mod is active the game crashes. And I am not even getting any error message. It just crashes. So I don't know where to look for the problem. I am fairly new to lua coding so is could be something pretty basic but I need some help on this one. The autor of the mentioned thread got the same problems and solved it by using 

modimport "scripts\\widgets\\happinesswidget.lua"

However this doesn't work for me. I tried to add ":" after "modimport" but it still crashes. Does anyone know what I am doing wrong?

 

 

-LesSV 

@LesSV,

your logfile with the error is probably in

C:\Users\youruser\Documents\Klei\DoNotStarveTogether\log.txt

reading some more tutorials probably wouldnt hurt either then:

http://forums.kleientertainment.com/topic/50811-guide-modding-practices-series-index/

Edited by Seiai

Okay, so I got the modimport to work. It needs to be in modmain.lua not in character.lua. Now I get the following error: 

[string "../mods/zoey/scripts/widgets/sha..."]:1: variable 'Widget' is not declared

so it is this line:

ShadowWidget = Class(GLOBAL.Widget, function(self, owner)

Just wanted you to know that I solved the first problem. 

That code has syntax errors everywhere.

ShadowWidget = 	GLOBAL.Class(GLOBAL.Widget, function(self, owner)        GLOBAL.Widget._ctor(self, "ShadowWidget")        self.owner = owner        self.base_scale = .5        self:SetScale(self.base_scale, self.base_scale, self.base_scale)        self:SetPosition(100, 20, 0)        self.text = self:AddChild(GLOBAL.Text(GLOBAL.NUMBERFONT, 40 / self.base_scale))        self.text:SetString("Test Widget Works!")end)local function initMod()    	local player = GLOBAL.GetPlayer()    	if player ~= nil and player.HUD ~= nil then        		player.HUD:AddChild(ShadowWidget(player.HUD.owner))	endendAddSimPostInit(initMod)

This makes more sense.

That code has syntax errors everywhere.

ShadowWidget = 	GLOBAL.Class(GLOBAL.Widget, function(self, owner)        GLOBAL.Widget._ctor(self, "ShadowWidget")        self.owner = owner        self.base_scale = .5        self:SetScale(self.base_scale, self.base_scale, self.base_scale)        self:SetPosition(100, 20, 0)        self.text = self:AddChild(GLOBAL.Text(GLOBAL.NUMBERFONT, 40 / self.base_scale))        self.text:SetString("Test Widget Works!")end)local function initMod()    	local player = GLOBAL.GetPlayer()    	if player ~= nil and player.HUD ~= nil then        		player.HUD:AddChild(ShadowWidget(player.HUD.owner))	endendAddSimPostInit(initMod)

This makes more sense.

 

 

Thank you for the input! I changed it but still get the error. I think it has something to do with the fact that this code is written for Don't Starve. Not DST. I have to research more.

@LesSV, you can append stuff to the HUD, or append stuff to other widgets.

The Always on Status mod does the second.

 

Wow dude. Thank you! That is exactly what I needed. I was looking at the Always On Status Mod myself when I saw your post. But it is difficult to understand for an amateur in lua coding like me. I will mess around with the code a bit more but I think my problem is solved!

 

 

Edit: It is not solved entirely. After fiddling around a bit I am stuck again. I wanted to rewrite your code that way that there is an image instead of a text. I took the Always On Status Mod as reference and changed the code to this:

local Widget = require "widgets/widget"local Image = require "widgets/image"local Text = require "widgets/text"local UIAnim = require "widgets/uianim"ShadowWidget = Class(Widget, function(self, owner)    	Widget._ctor(self, "ShadowWidget")    	self.owner = owner    	self.base_scale = .5    	self:SetScale(self.base_scale, self.base_scale, self.base_scale)    	self:SetPosition(200, 200, 200)    	self.image = self:AddChild(Image("images/rain.xml", "rain.tex"))end)return ShadowWidget

I took the rain.xml and rain.tex from the Always On Status Mod. But when running this I get an error. Then I tried other things out. I changed the .xml and .tex files to hud.xml and clock_wedge.tex. And what happened? It worked! So I tested the other .tex and .xml files from the AOS Mod and none of them work. But all of the native game files work. I created a custom .tex and .xml and those did not work neither. Where is my mistake? 

Edited by LesSV

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...