Yue Posted January 31, 2022 Posted January 31, 2022 When I collide with a stage element with collision trigger I get this error sporadically and the game closes. Any suggestions? function Script:Collision(entity, position, normal, speed) if entity:GetKeyValue("name") == "Yue" then if self.element == 0 then self.entity:Hide() self.Hud.script:ResetOxygen() if self.Hud.script.gOxygen == 1 then self.sOxygen:Play() end elseif self.element == 1 then if self.Hud.script.gLife < 128 then self.entity:Hide() self.Hud.script:ResetLife() if self.Hud.script.gLife < 120 then self.sRelief:Play() end end elseif self.element == 2 then -- Here Problem. self.entity:Release() --if self.Inv.script.Inv:GetEpo() < 5 then --self.pickUp:Play() self.Inv.script:AddEpo() --end end end end Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted January 31, 2022 Posted January 31, 2022 That's pretty rare. Probably a NULL being passed to a function. What line does it occur on? 1 Quote Let's build cool stuff and have fun.
Yue Posted January 31, 2022 Author Posted January 31, 2022 49 minutes ago, Josh said: That's pretty rare. Probably a NULL being passed to a function. What line does it occur on? I have simplified this to two lines of code. The error appears on collision. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
reepblue Posted January 31, 2022 Posted January 31, 2022 When you release the entity, you release the script. Never have an actor self remove itself. 2 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon!
Yue Posted January 31, 2022 Author Posted January 31, 2022 How can I do so that the code is not replicated inside the collision scrip. What happens is that I have to increment an inventory variable each time it takes a new element. Then the variable must rise from 0 ( it doesn't have the item ) to 1 when it takes that item. But what happens is that it goes to number 2. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted January 31, 2022 Posted January 31, 2022 Instead of releasing the entity you can just hide it. 1 Quote Let's build cool stuff and have fun.
Yue Posted January 31, 2022 Author Posted January 31, 2022 Yes, what happens is that if I hide it, it takes a while to disappear and the variable instead of increasing a value to 1 increases 2 or 3 values. variableItem = 0 Collision variableItem = variableItem + 1 But the result is not 1, but 2 or 3. I'm thinking of doing it outside the collider function with a fla Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Yue Posted January 31, 2022 Author Posted January 31, 2022 Ok, solved Here. Thanks YOu. -################################################## --# Proyecto : Astrocuco --# Scripter : Yue Rexie. --# Sitio Web : https://www.iris3dgames.xyz --# Fichero : Element.lua --################################################## --# Notas : Fichero enganchado a la entidad --# en contexto. --################################################## import("Scripts/Game/Sounds/CSound.lua") Script.element = 0 --choice "Element" "Oxygen, Health, Stamine" Script.state = 1 --choice "State" "Damage, Recovery, Inven" -- Pendiente. function Script:Start() self.Hud = World:GetCurrent():FindEntity("Hud") if self.element == 0 then self.sOxygen = CSound:Create("RecoveryOxygen") self.sOxygen:SetLoopMode(false) self.sOxygen:SetVolume(0.15) end if self.element == 1 then self.sRelief = CSound:Create("Relief") self.sRelief:SetLoopMode(false) self.sRelief:SetVolume(0.15) end if self.element == 2 then self.pickUp = CSound:Create("Cremallera") self.pickUp:SetLoopMode(false) self.pickUp:SetVolume(0.5) self.Inv = World:GetCurrent():FindEntity("Inventario") end self.collisionEpo = false end function Script:Collision(entity, position, normal, speed) if entity:GetKeyValue("name") == "Yue" then if self.element == 0 then self.entity:Hide() self.Hud.script:ResetOxygen() if self.Hud.script.gOxygen == 1 then self.sOxygen:Play() end elseif self.element == 1 then if self.Hud.script.gLife < 128 then self.entity:Hide() self.Hud.script:ResetLife() if self.Hud.script.gLife < 120 then self.sRelief:Play() end end elseif self.element == 2 then if self.Inv.script.Inv:GetEpo() < 5 then self.entity:Hide() self.pickUp:Play() self.collisionEpo = true end end end end function Script:UpdateWorld() -- Here variable change + 1. if self.collisionEpo == true then self.collisionEpo = false self.Inv.script:AddEpo() end if self.entity:GetKeyValue("name") == "KitHealth" then self.entity:Turn(0,0,2) elseif self.entity:GetKeyValue("name") == "Epo" then self.entity:Turn(1,1,1) end end 1 Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.