Jump to content

Recommended Posts

Hello! I've been tinkering with my mod so that my character can turn into a wolf. However, I get a crash when starting a new game with Bigby that involves how he transforms, which is by lowering his health to 75.

I have no clue as to what went wrong. I've attached the log and my character's prefab. Thanks!

bigby.lua

log.txt

@Mobbstar, Hey, I was wondering about another thing: How can I make a character break tools faster? I looked around the forums and found no similar power that I could replicate,and I couldn't find anything about it in the prefabs/components. 

inst:ListenForEvent("working",BreakTool)

 

with the corresponding function "BreakTool" somewhere above:

 

local BreakTool = function(inst, data)

--use data to access the tool

--alternatively use the inventory component to access the active item

end

@Mobbstar, I probably did this really stupidly, but why doesn't this work?

 

local BreakTool = function(inst, data)
 
  if inst.components.tool
       and data.percent and data.percent <= 20
       and inst.components.inventoryitem and inst.components.inventoryitem.owner then
        inst.components.inventoryitem.owner:PushEvent("toolbroke", {tool = inst})
    end
 
end
if inst.components.tool

 

--use data to access the tool

--alternatively use the inventory component to access the active item

 

local tool = inst and inst.components.inventory:GetActiveItem() --inst is wilson, we grab the tool using inventory ("inst and" is a hacky way to say "we've got that and... (or else...)"

 

if not tool then return end --we need a tool

 

local per = tool.components.finiteuses and tool.components.finiteuses:GetPercent()

 

if per <= 0.2 then --percent are usually written like that, because 100% is one whole, so 20% is .2

    tool.components.finiteuses:SetUses(0)
end

@Mobbstar, So I did it like this:

 

local BreakTool = function(inst, data)
 
 local tool = inst and inst.components.inventory:GetActiveItem() 
if not tool then return 
 
end 
 
local per = tool.components.finiteuses and tool.components.finiteuses:GetPercent()
 
if per <= 0.2 then 
    tool.components.finiteuses:SetUses(0)
end
  
end
 
 
And I can still use tools past 20%. Which part did I do wrong?

 

You did wrong in that you didn't place debug prints :p

 

print("If the console or log shows this text, that means this code block fired. I can also print variables like so ", inst, tool)

 

Try that, it's always helpful at narrowing the possible problems down.

@Mobbstar, I put in the print in the lua file, and the code did indeed block fire. What does this mean?

 

That means that wherever you put that code, the game went there successfully under those circumstances.

 

For you that means that you can test whether the if-block triggers. When it does, the only fault could be in the line that is meant to break the tool, when it doesn't, the fault is in the test.

 

The fault can even be in the stars, you just oughta study them to fix it. :p

@Mobbstar, So how would I go about testing the if-block? 

 

You... I... :(

 

Take the thing and put it in the thing and see if it things when you thing.

 

That's an if-block:

 

if [...] then

[...]

end

 

How would you go about testing it using the print function as shown above? What would you even test it for? (hint: I told you already, try to understaaaaannd! ooohhooooohh!)

 

EDIT

Edited by Mobbstar

@Mobbstar, I was able to figure the rest out. Thanks for the help! But I have one more problem: When I try to update my mod through DS mod tools it says the api version in the modinfo must be different then the current version, however I have the latest api version in there. What do I do? 

@Mobbstar, I was able to figure the rest out. Thanks for the help! But I have one more problem: When I try to update my mod through DS mod tools it says the api version in the modinfo must be different then the current version, however I have the latest api version in there. What do I do? 

 

The mod's version ( 1.0 -> 1.1 ) is described here.

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