Jump to content

Recommended Posts

Hello. I made simple sound playing prefab. Play sound command working but when i trying to stop playing its not working and i dont know why.  Help anyone?

local assets={   Asset("ANIM", "anim/record.zip"),        --[NEW] This is the FMOD file which contains all of the sound events.    Asset("SOUNDPACKAGE", "sound/tut07.fev"),    --[NEW] This is the FMOD file which contains all the actual sound data.    Asset("SOUND", "sound/tut07_bank69.fsb"),     Asset("ATLAS", "images/inventoryimages/record.xml"),    Asset("IMAGE", "images/inventoryimages/record.tex"),}prefabs = {}local function start(inst)                   inst.SoundEmitter:PlaySound("tut07/musicbox/dream")                 end        local function off(inst)                       inst.SoundEmitter:KillSound("dream")                       end            local function fn()          local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)          anim:SetBank("record")    anim:SetBuild("record")    anim:PlayAnimation("idle")     inst:AddComponent("inspectable")         inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "record"    inst.components.inventoryitem.atlasname = "images/inventoryimages/record.xml"        inst:AddTag("volume")                        inst.musicbox = TheSim:FindFirstEntityWithTag("musicbox")    if inst.musicbox then        inst.musicbox:ListenForEvent("start", function(entity) start(inst) end, inst.musicbox)          end                        if inst.musicbox then        inst.musicbox:ListenForEvent("off", function(entity) off(inst) end, inst.musicbox)           end            return inst             endreturn  Prefab("common/inventory/volume", fn, assets, prefabs)
Edited by EmielRegis
Link to comment
https://forums.kleientertainment.com/forums/topic/31805-sound-problem/
Share on other sites

The line where you choose to start the sound should look like this:

 

inst.SoundEmitter:PlaySound("tut07/musicbox/dream", "dream")

 

instead of this:

 

inst.SoundEmitter:PlaySound("tut07/musicbox/dream")

 

Tell me if that doesn't work, and I'll do my best to fix it.

Edited by JackSlender

The line where you choose to start the sound should look like this:

 

inst.SoundEmitter:PlaySound("tut07/musicbox/dream", "dream")

 

instead of this:

 

inst.SoundEmitter:PlaySound("tut07/musicbox/dream")

 

Tell me if that doesn't work, and I'll do my best to fix it.

Works perfectly, thank you very much :D

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
×
  • Create New...