Doodle Monster Posted August 13, 2025 Share Posted August 13, 2025 Hi! So as the title says, my function is currently crashing. The goal was to make a book that would give everyone in a area the thulicite crown bubble I'll add my perfab file and the crash here. Any help or pointers would be awesome! Also Keep in mind you might not get notifications if I reply, I think it's because I'm a new user so people aren't geting my messages. Anyways, here's the crash [00:00:39]: Mod: Wendalyn Book Sheild CODE (Wendalyn Book Shield) Registering prefabs [00:00:39]: Mod: Wendalyn Book Sheild CODE (Wendalyn Book Shield) Registering prefab file: prefabs/wendalyn_book_shield [00:00:39]: error calling LoadPrefabFile in mod Wendalyn Book Sheild CODE (Wendalyn Book Shield): [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wendalyn_book_shield [string "../mods/Wendalyn Book Sheild CODE/scripts/prefabs/wendalyn_book..."]:90: unexpected symbol near ')' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(160,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(191,1) scripts/mods.lua(690,1) in function '_RegisterPrefabs' local MS_MODNAME = 'workshop-2812783478';local a = {} wendalyn_book_shield_ground.zip wendalyn_book_shield_ground.scml wendalyn_book_shield_ground.zip wendalyn_book_shield.tex wendalyn_book_shield.xml modicon.xml modinfo.lua modmain.lua wendalyn_book_shield.lua I forgot to add, this was the function that's giving me problems. It's probably atrociously made because i'm very new to lua. reader:StartThread(function(inst, target) print(inst, target) local caster = inst.components.inventoryitem.owner caster = caster or target if SanityCheck(caster) then --target.components.health:DoDelta(25) --AOE local pt = target:GetPosition() local range = 10 local must_tags = {"player"} local players = TheSim:FindEntities(pt.x,pt.y,pt.z,range,must_tags) inst:AddTag("forcefield") if inst._fx ~= nil then inst._fx:kill_fx() end inst._fx = SpawnPrefab("forcefieldfx") inst._fx.entity:SetParent(owner.entity) inst._fx.Transform:SetPosition(0, 0.2, 0) inst.components.armor:SetAbsorption(TUNING.FULL_ABSORPTION) inst.components.armor.ontakedamage = function(inst, damage_amount) if owner ~= nil and owner.components.sanity ~= nil then owner.components.sanity:DoDelta(-damage_amount * TUNING.ARMOR_RUINSHAT_DMG_AS_SANITY, false) --All players in range 10 near target for _,v in ipairs(players) do end end if inst._task ~= nil then inst._task:Cancel() end inst._task = inst:DoTaskInTime(TUNING.ARMOR_RUINSHAT_DURATION, ruinshat_unproc) end) end reader.components.sanity:DoDelta(-30) return true end Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/ Share on other sites More sharing options...
FerniFrenito Posted August 14, 2025 Share Posted August 14, 2025 Hi again. I think you might have a parenthesis in the wrong place. reader:StartThread( function(inst, target) print(inst, target) local caster = inst.components.inventoryitem.owner caster = caster or target if SanityCheck(caster) then --target.components.health:DoDelta(25) --AOE local pt = target:GetPosition() local range = 10 local must_tags = {"player"} local players = TheSim:FindEntities(pt.x,pt.y,pt.z,range,must_tags) inst:AddTag("forcefield") if inst._fx ~= nil then inst._fx:kill_fx() end inst._fx = SpawnPrefab("forcefieldfx") inst._fx.entity:SetParent(owner.entity) inst._fx.Transform:SetPosition(0, 0.2, 0) inst.components.armor:SetAbsorption(TUNING.FULL_ABSORPTION) inst.components.armor.ontakedamage = function(inst, damage_amount) if owner ~= nil and owner.components.sanity ~= nil then owner.components.sanity:DoDelta(-damage_amount * TUNING.ARMOR_RUINSHAT_DMG_AS_SANITY, false) --All players in range 10 near target for _,v in ipairs(players) do end end if inst._task ~= nil then inst._task:Cancel() end inst._task = inst:DoTaskInTime(TUNING.ARMOR_RUINSHAT_DURATION, ruinshat_unproc) end // ) <-- you put a ) here end) <--- But apparently is here reader.components.sanity:DoDelta(-30) return true end I don't know if reader:StartThread(...) is inside a function, and if so, that last end would be closing that function. I can't read your Lua file because it's unavailable, but if you can provide it, I might be able to help solve your problem. 1 Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831881 Share on other sites More sharing options...
Doodle Monster Posted August 15, 2025 Author Share Posted August 15, 2025 Thanks for takeing the time to look at it! I'll see if I can put the lua file in here. This is the entire prefab file, let me know if you need the modmain or anything else. I'll test it with the changes when I can! local Assets = { -- Animation files for the item (showing it on the ground and swap symbols for the players). Asset("ANIM", "anim/wendalyn_book_shield_ground.zip"), -- Inventory image and atlas file used for the item. Asset("ATLAS", "images/inventoryimages/wendalyn_book_shield.xml"), Asset("IMAGE", "images/inventoryimages/wendalyn_book_shield.tex"), } WENDALYNSHIELD = 15 local function MainFunction() -- Functions which are performed both on Client and Server start here. local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) -- Add minimap icon. Remember about its XML in modmain.lua! local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon("wendalyn_book_shield.tex") --[[ ANIMSTATE ]]-- -- This is the name visible on the top of hierarchy in Spriter. inst.AnimState:SetBank("wendalyn_book_shield_ground") -- This is the name of your compiled*.zip file. inst.AnimState:SetBuild("wendalyn_book_shield_ground") -- This is the animation name while item is on the ground. inst.AnimState:PlayAnimation("anim") --[[ TAGS ]]-- inst:AddTag("wendalyn_book_shield") inst:AddTag("book") inst:AddComponent("book") local function ruinshat_unproc(inst) if inst:HasTag("forcefield") then inst:RemoveTag("forcefield") if inst._fx ~= nil then inst._fx:kill_fx() inst._fx = nil end if inst._task ~= nil then inst._task:Cancel() end end end inst.components.book.onread = function(inst, reader) local x,y,z = reader.Transform:GetWorldPosition() local pt = reader:GetPosition() reader:StartThread(function(inst, target) print(inst, target) local caster = inst.components.inventoryitem.owner caster = caster or target if SanityCheck(caster) then --target.components.health:DoDelta(25) --AOE local pt = target:GetPosition() local range = 10 local must_tags = {"player"} local players = TheSim:FindEntities(pt.x,pt.y,pt.z,range,must_tags) inst:AddTag("forcefield") if inst._fx ~= nil then inst._fx:kill_fx() end inst._fx = SpawnPrefab("forcefieldfx") inst._fx.entity:SetParent(owner.entity) inst._fx.Transform:SetPosition(0, 0.2, 0) inst.components.armor:SetAbsorption(TUNING.FULL_ABSORPTION) inst.components.armor.ontakedamage = function(inst, damage_amount) if owner ~= nil and owner.components.sanity ~= nil then owner.components.sanity:DoDelta(-damage_amount * TUNING.ARMOR_RUINSHAT_DMG_AS_SANITY, false) --All players in range 10 near target for _,v in ipairs(players) do end end if inst._task ~= nil then inst._task:Cancel() end inst._task = inst:DoTaskInTime(TUNING.ARMOR_RUINSHAT_DURATION, ruinshat_unproc) end) end reader.components.sanity:DoDelta(-30) return true end MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2}) inst.entity:SetPristine() if not TheWorld.ismastersim then -- If we're not the host - stop performing further functions. -- Only server functions below. return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "wendalyn_book_shield" inst.components.inventoryitem.atlasname = "images/inventoryimages/wendalyn_book_shield.xml" --new new code MakeHauntableLaunch(inst) return inst end return Prefab("common/inventory/wendalyn_book_shield", MainFunction, Assets) Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831948 Share on other sites More sharing options...
FerniFrenito Posted August 15, 2025 Share Posted August 15, 2025 Okay. Now that I see the complete code, I'm absolutely sure the error was caused by what I mentioned. I'll wait for your reply. Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831955 Share on other sites More sharing options...
Doodle Monster Posted August 15, 2025 Author Share Posted August 15, 2025 Okay, so It's not crashing anymore! but the game freezes upon trying to read unstopable I'll try and see if there's anything in the client log. (It's frozen on this screen) Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831967 Share on other sites More sharing options...
Doodle Monster Posted August 15, 2025 Author Share Posted August 15, 2025 (edited) Okay, here's what I got from the client log: COROUTINE 118463 SCRIPT CRASH: [string "../mods/Wendalyn Book Sheild/scripts/prefab..."]:66: attempt to index local 'inst' (a nil value) LUA ERROR stack traceback: ../mods/Wendalyn Book Sheild/scripts/prefabs/wendalyn_book_shield.lua(66,1) [00:02:54]: COROUTINE 118463 SCRIPT CRASH: [string "../mods/Wendalyn Book Sheild/scripts/prefab..."]:66: attempt to index local 'inst' (a nil value) LUA ERROR stack traceback: ../mods/Wendalyn Book Sheild/scripts/prefabs/wendalyn_book_shield.lua(66,1) [00:02:54]: LuaError but no error string [00:05:34]: Server Paused [00:05:35]: Server Unpaused [00:05:38]: DoRestart: true Edited August 15, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831969 Share on other sites More sharing options...
FerniFrenito Posted August 16, 2025 Share Posted August 16, 2025 Hi, I would need to see your code 'Wendalyn Book Sheild/scripts/prefabs/wendalyn_book_shield.lua'. I don't think it's the one you sent me because if it were, it would give an error much earlier. Now, the error indicates that 'inst' is null and therefore you cannot access anything from that object, as it does not exist. From experience, it is very likely due to you receiving 'inst' as a parameter, but you forget that when building an object, one parameter is passed before all the others, which as I recall is the object that instantiated the class. Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1831997 Share on other sites More sharing options...
Edible Coal Posted August 16, 2025 Share Posted August 16, 2025 local Assets = { -- Animation files for the item (showing it on the ground and swap symbols for the players). Asset("ANIM", "anim/wendalyn_book_shield_ground.zip"), -- Inventory image and atlas file used for the item. Asset("ATLAS", "images/inventoryimages/wendalyn_book_shield.xml"), Asset("IMAGE", "images/inventoryimages/wendalyn_book_shield.tex"), } local WENDALYNSHIELD = 3 local function ruinshat_unproc(inst) if inst:HasTag("forcefield") then inst:RemoveTag("forcefield") if inst._fx ~= nil then inst._fx:kill_fx() inst._fx = nil end if inst._task ~= nil then inst._task:Cancel() end end if inst.components.health ~= nil then --player.components.health.externalabsorbmodifiers:SetModifier(player, TUNING.BUFF_PLAYERABSORPTION_MODIFIER) inst.components.health:SetAbsorptionAmount(0) end end local function MainFunction() -- Functions which are performed both on Client and Server start here. local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) -- Add minimap icon. Remember about its XML in modmain.lua! local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon("wendalyn_book_shield.tex") --[[ ANIMSTATE ]]-- -- This is the name visible on the top of hierarchy in Spriter. inst.AnimState:SetBank("wendalyn_book_shield_ground") -- This is the name of your compiled*.zip file. inst.AnimState:SetBuild("wendalyn_book_shield_ground") -- This is the animation name while item is on the ground. inst.AnimState:PlayAnimation("anim") --[[ TAGS ]]-- inst:AddTag("wendalyn_book_shield") inst:AddTag("book") inst:AddComponent("book") --[[affected players]]-- if you need this.... inst._ruins_proc_players={} inst.components.book.onread = function(inst, reader) reader:StartThread(function() local x,y,z = reader.Transform:GetWorldPosition() if true then --SanityCheck(caster) local range = 10 local must_tags = {"player"} local players = TheSim:FindEntities(x,y,z,range,must_tags) table.insert(inst._ruins_proc_players,players) if players ~=nil then for key,player in pairs(players) do --[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system player:AddTag("forcefield") if player._fx ~= nil then player._fx:kill_fx() end player._fx = SpawnPrefab("forcefieldfx") player._fx.entity:SetParent(player.entity) player._fx.Transform:SetPosition(0, 0.2, 0) if player.components.health ~= nil then player.components.health:SetAbsorptionAmount(1) end if player._task ~= nil then player._task:Cancel() end player._task = player:DoTaskInTime(WENDALYNSHIELD, ruinshat_unproc) end end end end) reader.components.sanity:DoDelta(-30) return true end MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2}) inst.entity:SetPristine() if not TheWorld.ismastersim then -- If we're not the host - stop performing further functions. -- Only server functions below. return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "wendalyn_book_shield" inst.components.inventoryitem.atlasname = "images/inventoryimages/wendalyn_book_shield.xml" --new new code MakeHauntableLaunch(inst) return inst end return Prefab("wendalyn_book_shield", MainFunction, Assets) Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832001 Share on other sites More sharing options...
Doodle Monster Posted August 16, 2025 Author Share Posted August 16, 2025 Thank you for the fix! I'm still pretty new to lua, Do you have any resources on learning? Anyways thank you guys so much for the help! Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832016 Share on other sites More sharing options...
Doodle Monster Posted August 16, 2025 Author Share Posted August 16, 2025 Just tested it, it works. Thank you guys so much for the help! Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832028 Share on other sites More sharing options...
Edible Coal Posted August 17, 2025 Share Posted August 17, 2025 11 hours ago, Doodle Monster said: Just tested it, it works. Thank you guys so much for the help! what else you need ? Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832071 Share on other sites More sharing options...
Doodle Monster Posted August 18, 2025 Author Share Posted August 18, 2025 @Edible Coal So, I was trying to add another book that would do something similar but with a damage bonus. Problem is I can't get the FX to dissapear when it runs out and inst._fx:kill_fx() isn't working, i'll put the code in here if you get a chance to look at it that would be really great. local Assets = { -- Animation files for the item (showing it on the ground and swap symbols for the players). Asset("ANIM", "anim/wendalyn_book_damage_ground.zip"), -- Inventory image and atlas file used for the item. Asset("ATLAS", "images/inventoryimages/wendalyn_book_damage.xml"), Asset("IMAGE", "images/inventoryimages/wendalyn_book_damage.tex"), } local WENDALYNSHIELD = 60 local function starcrushed_unproc(inst) if inst:HasTag("starcrushed") then inst:RemoveTag("starcrushed") inst.components.talker:Say("Guess the starcrushing is over.") if inst._back ~= nil then inst._back:Remove() end if inst._task ~= nil then inst._task:Cancel() end end if inst.components.combat ~= nil then --player.components.health.externalabsorbmodifiers:SetModifier(player, TUNING.BUFF_PLAYERABSORPTION_MODIFIER) inst.components.combat.damagemultiplier = 1 end end local function MainFunction() -- Functions which are performed both on Client and Server start here. local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) -- Add minimap icon. Remember about its XML in modmain.lua! local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon("wendalyn_book_damage.tex") --[[ ANIMSTATE ]]-- -- This is the name visible on the top of hierarchy in Spriter. inst.AnimState:SetBank("wendalyn_book_damage_ground") -- This is the name of your compiled*.zip file. inst.AnimState:SetBuild("wendalyn_book_damage_ground") -- This is the animation name while item is on the ground. inst.AnimState:PlayAnimation("anim") --[[ TAGS ]]-- inst:AddTag("wendalyn_book_damage") inst:AddTag("book") inst:AddComponent("book") --[[affected players]]-- if you need this.... inst._ruins_proc_players={} inst.components.book.onread = function(inst, reader) reader:StartThread(function() local x,y,z = reader.Transform:GetWorldPosition() if true then --SanityCheck(caster) local range = 10 local must_tags = {"player"} local players = TheSim:FindEntities(x,y,z,range,must_tags) table.insert(inst._ruins_proc_players,players) if players ~=nil then for key,player in pairs(players) do --[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system player:AddTag("starcrushed") if player._fx ~= nil then player._fx = nil end player._fx = SpawnPrefab("slingshotammo_purebrilliance_debuff_fx") player._fx.entity:SetParent(player.entity) player._fx.Transform:SetPosition(0, 0.2, 0) if player.components.combat ~= nil then player.components.combat.damagemultiplier = 1.25 player.components.talker:Say("Time to dish it out!") end if player._task ~= nil then player._task:Cancel() end player._task = player:DoTaskInTime(WENDALYNSHIELD, starcrushed_unproc) end end end end) reader.components.sanity:DoDelta(-35) return true end MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2}) inst.entity:SetPristine() if not TheWorld.ismastersim then -- If we're not the host - stop performing further functions. -- Only server functions below. return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "wendalyn_book_damage" inst.components.inventoryitem.atlasname = "images/inventoryimages/wendalyn_book_damage.xml" --new new code MakeHauntableLaunch(inst) return inst end return Prefab("wendalyn_book_damage", MainFunction, Assets) Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832181 Share on other sites More sharing options...
Doodle Monster Posted August 21, 2025 Author Share Posted August 21, 2025 I did get a version to work with both books! Problem is I can't use a fx that stays on the player for now because I don't know how to remove it properly. Link to comment https://forums.kleientertainment.com/forums/topic/167569-help-reading-function-crashing/#findComment-1832464 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