Eusong Posted September 18, 2017 Share Posted September 18, 2017 I'm trying to make an item that modifies a component when a player is near it. I'm experiencing a crash and there's no log. I know how to check for one- there is no log. At all. Sooo....I'm stumped. Any thoughts of what could be wrong? Spoiler local assets = { Asset("ANIM", "anim/radrubble.zip"), } local prefabs = { } function FindEntity(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 20, {"player"}) for i, v in ipairs(ents) do ents.components.rads.current = ents.components.rads.current + 0.05 end end local function onhammered(inst, worker) local fx = SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) fx:SetMaterial("rock") local pos = inst:GetPosition() local broken = SpawnPrefab("rocks") broken.Transform:SetPosition(pos:Get()) inst:Remove() end local function common_fn(anim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddMiniMapEntity() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeObstaclePhysics(inst, .5) --inst.MiniMapEntity:SetPriority(5) --inst.MiniMapEntity:SetIcon(name..".png") inst.AnimState:SetBank("radrubble") inst.AnimState:SetBuild("radrubble") inst.AnimState:PlayAnimation(anim) inst:AddTag("antlion_sinkhole_blocker") inst:AddTag("radioactive") 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:SetOnFinishCallback(onhammered) inst:DoPeriodicTask(1, FindEntity(inst), nil) return inst end local function radrubble1_fn() local inst = common_fn("radrubble1") if not TheWorld.ismastersim then return inst end inst.components.workable:SetWorkLeft(1) return inst end local function radrubble2_fn() local inst = common_fn("radrubble2") if not TheWorld.ismastersim then return inst end inst.components.workable:SetWorkLeft(3) return inst end local function radrubble3_fn() local inst = common_fn("radrubble3") if not TheWorld.ismastersim then return inst end inst.components.workable:SetWorkLeft(3) return inst end return Prefab("radrubble1", radrubble1_fn, assets, prefabs), Prefab("radrubble2", radrubble2_fn, assets, prefabs), Prefab("radrubble3", radrubble3_fn, assets, prefabs) Link to comment Share on other sites More sharing options...
ptr Posted September 18, 2017 Share Posted September 18, 2017 You can insert some asserts or prints to track your code. By the way, FindEntity is a global function defined in simutil.lua, redefining it may cause some serious problem. So rename it or make it local. Link to comment Share on other sites More sharing options...
ptr Posted September 18, 2017 Share Posted September 18, 2017 Shouldn't it be v instead of ents? for i, v in ipairs(ents) do ents v.components.rads.current = ents v.components.rads.current + 0.05 end Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now