Jump to content

Recommended Posts

I have used a tutorial on the forums to create a 4th meter, I wanted this meter to increase and decrease in certain circumstances, I assumed that inst.components.anxiety.dapperness = 1 would cause it to increase when it was in a if statement I created, however upon testing it states that "attempt to index field "anxiety" (a nil value)", the error originates from the inst.components line, just so you know.

I've looked all over and couldn't find a answer that worked, I'm hoping one again asking could yield more answers to my specific requirements, below is the code for the meter in the specific files for anyone who may be curious.
Modmain.lua

-- Anxiety
anxiety  = require "widgets/anxiety"
AddClassPostConstruct("widgets/statusdisplays", function(self)
if self.owner.prefab ~= 'loki' then
     return
end
self.pos = self:AddChild(anxiety(self.owner))
local ANXIETYMETER = GetModConfigData("ANXIETYMETER")
if ANXIETYMETER == 0 then
    self.pos:SetPosition(-80, -40, 0)
    self.pos:MoveToBack()	
end
if ANXIETYMETER == 1 then
    self.pos:SetPosition(0, 0, 0)
    self.pos:MoveToBack()	
end
if ANXIETYMETER == 2 then
    self.pos:SetPosition(-125, 35, 0)
    self.pos:MoveToBack()	
end
end)

anxiety.lua (Inside the Widgets folder)

local Badge = require "widgets/badge"

local anxiety  = Class(Badge, function(self, owner)
    Badge._ctor(self, nil, owner, { 225 / 0, 0 / 0, 0 / 0, 0 })
    self.owner = owner
    self.num.max = 100
    self.num.current = self.num.max

    owner:ListenForEvent("axtydirty",function(owner,data)

        self.num.current = self.owner.axty:value()
        self.percent =  self.owner.axty:value()  / self.num.max
    end)

    self:StartUpdating() -- does uhhhhhgh something
end)

function anxiety:OnUpdate(dt)
    if self.owner ~= nil and self.owner.axty ~= nil then
        local percent = self.owner.axty:value() / self.num.max
        self:SetPercent(percent,self.num.max)
    end
end

return anxiety

Character Prefab file (Parts that have to do with the anxiety meter anyway)
 

local common_postinit = function(inst) 
	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "loki.tex" )

    inst.axty = net_ushortint(inst.GUID, "axty", "axtydirty" )

    inst.axty:set(0)

    inst.axty:value()
end

if m:GetMoisture() >= 99 then
                inst:AddTag("Wet")
                inst.components.locomotor.walkspeed = 1
                inst.components.locomotor.runspeed = 1
                inst.components.anxiety.dapperness = 1
            end


local function OnSave(inst, data)
    data.axty = inst.axty:value()
end

local function OnLoad(inst, data)
    if data and data.axty then
        inst.axty:set(data.axty)
    end
end

If YOU yes YOU reading this post, have any idea on what I've done wrong, please, tell me, thank you kindly!

I don't fully understand what this snippet is supposed to do

if m:GetMoisture() >= 99 then
                inst:AddTag("Wet")
                inst.components.locomotor.walkspeed = 1
                inst.components.locomotor.runspeed = 1
                inst.components.anxiety.dapperness = 1
            end

It doesn't seem to be placed inside a function, unless you just cut it out and put it here. anxiety being nil might be because you didn't add it to your character using AddComponent(), but it's hard to tell just from these snippets alone.

15 minutes ago, -t- said:

I don't fully understand what this snippet is supposed to do

if m:GetMoisture() >= 99 then
                inst:AddTag("Wet")
                inst.components.locomotor.walkspeed = 1
                inst.components.locomotor.runspeed = 1
                inst.components.anxiety.dapperness = 1
            end

It doesn't seem to be placed inside a function, unless you just cut it out and put it here. anxiety being nil might be because you didn't add it to your character using AddComponent(), but it's hard to tell just from these snippets alone.

Oh ye it's cut out and inside a function sorry for being unclear with that, it's just a function that senses the moisture level, I will try the AddComponent() as I think I might have forgotten that indeed, thank you

5 hours ago, -t- said:

Sorry for the late response. I've looked through your character file and as I said you don't have anxiety added as a component. You need to put inst:AddComponent("anxiety") inside master_postinit.

Thank you for the help, the lateness is better than the neverness hahaha! I did try putting this about in the file but I never did do it in the masterpostinit, there is still 1 problem, I still remain to get a error when loading in as my character,

module "components/anxiety" not found

I honestly have no idea if I've done something wrong with my file layout or what, there is no folder inside my modded character called components, I tried making one and putting the widgets folder inside it however it just caused the game to crash

So you don't have the anxiety component created. That's the problem. Any meters that characters have are usually composed of a badge and a component. The badge is to visually represent the meter. A component is created to run the logic of that meter, so gaining/losing values or adding perks/debuffs.

Take the health meter for example.
It has the badge part that has some functions to manage how much health it should show and is placed inside StatusDisplays.
And it has the component part that manages the actual value with many functions related to that stat.

There's also the subject of networking, since anxiety is supposed to have effects on the player (server sided) and the UI (client sided). The server and the client have basically 2 separate, for lack of a better word, 'environments' and it's necessary to keep them in sync with each other. For that you would need a replica.

So, ultimately you'll need:
1. A badge
2. A component
3. A component replica

 

I won't explain every one of these here, since there is a bit to explain, but I advise you search a bit through the forums and the games code, mainly widgets/healthbadge.lua, components/health.lua and components/replica_health.lua.

Here're some posts you might find useful:

 

On 4/5/2023 at 6:13 PM, -t- said:

So you don't have the anxiety component created. That's the problem. Any meters that characters have are usually composed of a badge and a component. The badge is to visually represent the meter. A component is created to run the logic of that meter, so gaining/losing values or adding perks/debuffs.

Take the health meter for example.
It has the badge part that has some functions to manage how much health it should show and is placed inside StatusDisplays.
And it has the component part that manages the actual value with many functions related to that stat.

There's also the subject of networking, since anxiety is supposed to have effects on the player (server sided) and the UI (client sided). The server and the client have basically 2 separate, for lack of a better word, 'environments' and it's necessary to keep them in sync with each other. For that you would need a replica.

So, ultimately you'll need:
1. A badge
2. A component
3. A component replica

 

I won't explain every one of these here, since there is a bit to explain, but I advise you search a bit through the forums and the games code, mainly widgets/healthbadge.lua, components/health.lua and components/replica_health.lua.

Here're some posts you might find useful:

 

Oh my days, thank you so much, although there's still parts I'm struggling with I have at least got my mod to stop crashing every time I load it up now and I know what and where to look for information on how to get it all up and running, I would have never guessed I needed yet another file, I thought it was what the widget was for but alas now I know, again thank you so much this has been a real great help!

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...