Jump to content

Need help fixing character mod crash


Recommended Posts

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

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

@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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

@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? 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...