Jump to content

New Protoyper crashes game, please help


Recommended Posts

Hi, so this is another thing I am working on. A new prototyper. In the end this thing should make two new recipes under the REFINE tab available when standing near it! So far, I haven`t implemented these functions yet, because I cannot make it to a point where my game is stable, when placing the thing.

I looked at old threads about prototypers, I even used one as an almost exact base for this one, but still, it crashes to the desktop without any error log.

 

 

require "prefabutil"
require "recipe"
require "modutil"


local assets =
{
    Asset("ANIM", "anim/quagmire_mealingstone.zip"),
    Asset( "IMAGE", "images/inventoryimages/mealingstone.tex" ),
    Asset( "ATLAS", "images/inventoryimages/mealingstone.xml" ),
}

local prefabs =
{
    "collapse_small",
}

local function onbuilt(inst)
    inst.AnimState:PlayAnimation("place")
    inst.AnimState:PushAnimation("idle")
    inst.SoundEmitter:PlaySound("dontstarve/common/cook_pot_craft")

    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("stone")
end

local function doonact(inst)
    if inst._activecount > 1 then
        inst._activecount = inst._activecount - 1
    else
        inst._activecount = 0
        inst.SoundEmitter:KillSound("sound")
    end

    inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_lvl3_ding")
end

        local function doneact(inst)
        inst._activetask = nil
        if not inst:HasTag("burnt") then
            if inst.components.prototyper.on then
                OnTurnOn(inst)
            else
                OnTurnOff(inst)
            end
        end
    end

function OnTurnOn(inst)
    if inst.AnimState:IsCurrentAnimation("proximity_loop") then
        --NOTE: push again even if already playing, in case an idle was also pushed
        inst.AnimState:PushAnimation("proximity_loop", true)
    else
        inst.AnimState:PlayAnimation("proximity_loop", true)
    end
    if not inst.SoundEmitter:PlayingSound("dontstarve/creatures/together/clayhound/stone_shake") then
        inst.SoundEmitter:PlaySound("dontstarve/creatures/together/clayhound/stone_shake")
    end
end
 
function OnTurnOff(inst)
    inst.AnimState:PushAnimation("idle")
end

    local function onactivate(inst)
        if not inst:HasTag("burnt") then
            inst.AnimState:PlayAnimation("proximity_loop")
            inst.AnimState:PushAnimation("idle", false)
            if not inst.SoundEmitter:PlayingSound("dontstarve/creatures/together/clayhound/stone_shake") then
                inst.SoundEmitter:PlaySound("dontstarve/creatures/together/clayhound/stone_shake")
            end
            inst._activecount = inst._activecount + 1
            inst:DoTaskInTime(1.5, doonact)
            if inst._activetask ~= nil then
                inst._activetask:Cancel()
            end
            inst._activetask = inst:DoTaskInTime(inst.AnimState:GetCurrentAnimationLength() + 2 * FRAMES, doneact)
        end
    end

----------------------------------

local function onpreload(inst, data)
    --if data ~= nil and data.is_already_built ~= nil and inst.is_already_built == nil then
    --    inst.is_already_built = data.is_already_built
    --end
end

local function onsave(inst, data)
    --if data and inst.is_already_built ~= nil then
    --    data.is_already_built = inst.is_already_built
    --end
    
    -- if inst:HasTag("burnt") or (inst.components.burnable ~= nil and inst.components.burnable:IsBurning()) then
 --        data.burnt = true
 --    end
end

local function onload(inst, data)
    -- if data ~= nil and data.burnt then
 --        inst.components.burnable.onburnt(inst)
 --    end
end
----------------------------------

local function onhammered(inst, worker)
    if inst.components.burnable ~= nil and inst.components.burnable:IsBurning() then
        inst.components.burnable:Extinguish()
    end
    inst.components.lootdropper:DropLoot()
    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("stone")
    inst:Remove()
end

local function onhit(inst, worker)
    
end

-----------------------------------


local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()

    MakeObstaclePhysics(inst, .4)

    inst.MiniMapEntity:SetPriority(5)
    inst.MiniMapEntity:SetIcon("quagmire_mealingstone.png")

    inst.AnimState:SetBank("quagmire_mealingstone")
    inst.AnimState:SetBuild("quagmire_mealingstone")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("structure")

    --prototyper (from prototyper component) added to pristine state for optimization
    inst:AddTag("prototyper")

    MakeSnowCoveredPristine(inst)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
    
    inst:AddComponent("inspectable")

    inst:AddComponent("workable")
    inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
    inst.components.workable:SetWorkLeft(4)
    inst.components.workable:SetOnFinishCallback(onhammered)
    inst.components.workable:SetOnWorkCallback(onhit)

    inst:AddComponent("prototyper")
    inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.TECH.SCIENCE_ONE
    inst.components.prototyper.onturnon = OnTurnOn
    inst.components.prototyper.onturnoff = OnTurnOff
    inst.components.prototyper.onactivate = onactivate
    
    inst:ListenForEvent("onbuilt", onbuilt)

    inst.OnSave = onsave 
    inst.OnLoad = onload
    inst.OnPreLoad = onpreload

    return inst
end

return Prefab("mealingstone", fn, assets, prefabs),
    MakePlacer("mealingstone_placer", "quagmire_mealingstone", "quagmire_mealingstone", "idle")

 

Could anyone please have a look at it? Thank you very much! I don`t know what`s wrong there :(

Edited by Gobbel
Link to comment
Share on other sites

If there are no server logs yet, neither in the Master or Caves folder, then the client_log.txt might still have some information of what's happening. I'll try it out myself right now, though.

I got an error in my server_log.txt, so I could discern the error.

Line 165 in mealingstone.lua needs to be:

inst.components.prototyper.trees = TECH.SCIENCE_ONE

 

Link to comment
Share on other sites

Thank you so much, I love you man! I`ll change that immediately. Such a simple mistake drove me nuts and I couldn`t figure it out. QQ

 

Can I ask you one more thing? If I want the new recipes to only be available when the player is near the new prototyper I don`t have to add any new code, do I? Because the  

    inst.components.prototyper.onturnon = OnTurnOn
    inst.components.prototyper.onturnoff = OnTurnOff
    inst.components.prototyper.onactivate = onactivate

already does that, as far as I understood.

 

Because after adding  

  inst:AddTag("mealermealer")

to the prototyper and adding that tag in the two new recipes

local flour_recipe = Recipe("flour",{ Ingredient("wheat", 2) },                     
        RECIPETABS.REFINE, {SCIENCE = 0}, nil, nil, true, nil, "mealermealer")
        flour_recipe.atlas = "images/inventoryimages/flour.xml"

local turnip_sugar_recipe = Recipe("sugar",{ Ingredient("turnip", 2) },                     
        RECIPETABS.REFINE, {SCIENCE = 0}, nil, nil, true, nil, "mealermealer")
        turnip_sugar_recipe.atlas = "images/inventoryimages/turnip_sugar.xml"

, it crashes when it opens the crafting menu when standing near the prototyper.

 

[00:02:24]: [string "scripts/components/builder.lua"]:193: attempt to index field 'accessible_tech_trees' (a nil value)
LUA ERROR stack traceback:
    scripts/components/builder.lua:193 in (method) EvaluateTechTrees (Lua) <137-245>
    scripts/components/builder.lua:110 in (method) OnUpdate (Lua) <109-111>
    scripts/update.lua:192 in () ? (Lua) <149-228>
    
[00:02:24]: Warning: Widget:SetFocusFromChild is happening on a widget outside of the screen/widget hierachy. This will cause focus moves to fail. Is     ScriptErrorWidget    not a screen?    
[00:02:24]: stack traceback:
    scripts/widgets/widget.lua:602 in (method) SetFocusFromChild (Lua) <599-624>
    scripts/widgets/widget.lua:621 in (method) SetFocusFromChild (Lua) <599-624>
    scripts/widgets/widget.lua:621 in (method) SetFocusFromChild (Lua) <599-624>
    scripts/widgets/widget.lua:649 in (method) SetFocus (Lua) <626-658>
    scripts/widgets/menu.lua:83 in (method) SetFocus (Lua) <74-85>
    scripts/widgets/scripterrorwidget.lua:109 in (method) OnUpdate (Lua) <102-119>
    scripts/update.lua:90 in () ? (Lua) <33-129>    

 

EDIT: let me guess, it is something with the tech tree cannot be 0, right?

Edited by Gobbel
Link to comment
Share on other sites

Could you help me out one more time please? As I wrote above I added the tags to both the prototyper and the new recipes. ("mealermealer")

But, even if there is no crash at all now, because I set all the tech trees to 1 instead of 0, the recipes won`t show up. I guess it is because of the tags. How is it possible to have these new recipes linked to the new prototyper only without creating a new tech tree? Or do I absolutely have to create one?

 

Sorry for being such a trouble, but your knowledge is just too great a temptation to ask you. :)

Link to comment
Share on other sites

Well, I'm no expert, but as far as I understand it, the recipes are always tied to a TECH. If they're supposed to always be available, that TECH is TECH.NONE. Just add a new TECH with a custom (uppercase) name, which has a value for your custom tech-type (which you will need to add to AVAILABLE_TECH), and use your TECH in your recipes.

Look in the game file techtree.lua, which has the vanilla techtree types in a list called AVAILABLE_TECH, and look at constants.lua, which sets up the TECH dictionary. Just add to those, before creating your recipes.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...