EmielRegis Posted February 18, 2014 Share Posted February 18, 2014 Hello. I trying to make one item react to actions performed o another item. I have found example in "maxwellphonograph.lua" In "maxwellphonograph.lua" is this:local function stop(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:KillSound("ragtime") inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end") inst:PushEvent("turnedoff")endand in "maxwellendgame.lua" is:inst.phonograph = TheSim:FindFirstEntityWithTag("maxwellphonograph") if inst.phonograph then inst:ListenForEvent("turnedon", function() phonographon(inst) end, inst.phonograph) inst:ListenForEvent("turnedoff",function() phonographoff(inst) end, inst.phonograph) endI tried to copy it for my purpose: Thats one item file:local widgetbuttoninfo = { text = "Play", position = Vector3(0, -80, 0), fn = function(inst) --if inst.components.container:IsEmpty() == false then inst:PushEvent("start") --end end, }and another item, receiver:inst.musicbox = TheSim:FindFirstEntityWithTag("musicbox") if inst.musicbox then inst:ListenForEvent("start", function() start(inst) end, inst.musicbox) -- inst:ListenForEvent("turnedoff",function() phonographoff(inst) end, inst.phonograph) endlocal function start(inst) inst.SoundEmitter:PlaySound("tut07/musicbox/dream") endMaybe someone know why its not working? Link to comment Share on other sites More sharing options...
kraken121 Posted February 18, 2014 Share Posted February 18, 2014 my guess would be that inst var in first file fires on another 'object' than inst in 2nd fileso you're listening on start event on 'container' level instead of musicbox level basically it sounds like inst:ListenForEvent("start", should be replaced with inst.musicbox:ListenForEvent, or wherever the reference to the button is Link to comment Share on other sites More sharing options...
EmielRegis Posted February 18, 2014 Author Share Posted February 18, 2014 my guess would be that inst var in first file fires on another 'object' than inst in 2nd fileso you're listening on start event on 'container' level instead of musicbox level basically it sounds like inst:ListenForEvent("start", should be replaced with inst.musicbox:ListenForEvent, or wherever the reference to the button is not working Link to comment Share on other sites More sharing options...
seronis Posted February 19, 2014 Share Posted February 19, 2014 decided to make you a little example mod to show how the events work--[[Rabbits will die of depression if they see you eat a carrot--]]local function handlecarrot(rabbit,data) player = GLOBAL.GetPlayer() local distsq = rabbit:GetDistanceSqToInst(player) if distsq <= 20*20 then if data.food and data.food.prefab == "carrot" then rabbit.components.combat:GetAttacked(player, TUNING.GRUEDAMAGE) end endendlocal function doTweakRabbit(inst) player = GLOBAL.GetPlayer() inst:ListenForEvent( "oneatsomething", function(entity,data) handlecarrot(inst,data) end, player )endAddPrefabPostInit("rabbit", doTweakRabbit) Link to comment Share on other sites More sharing options...
EmielRegis Posted February 19, 2014 Author Share Posted February 19, 2014 decided to make you a little example mod to show how the events workI assuming that AddPrefabPostInit("rabbit", doTweakRabbit) is important but in game i have error:Here is code: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") endlocal function start2(inst) inst.musicbox = TheSim:FindFirstEntityWithTag("musicbox") if inst.musicbox then inst.musicbox:ListenForEvent("start", function(entity) start(inst) end, inst.musicbox) -- inst:ListenForEvent("turnedoff",function() phonographoff(inst) end, inst.phonograph) endend AddPrefabPostInit("volume", start2)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") return inst endreturn Prefab("common/inventory/volume", fn, assets, prefabs) Link to comment Share on other sites More sharing options...
seronis Posted February 19, 2014 Share Posted February 19, 2014 you use the prefab post init callbacks in order to hook in to when things are spawned in game. It gives you an opportunity to edit those objects the moment they are created. Its a call that belongs in your modmain.lua file in the root folder of your mod so in your case that would mean mods/dysk/modmain.lua If you are creating your own prefab (volume.lua) then you wouldnt need to also use that hook. You are writing the entire file so you would just initialize it how you want. In my example since rabbits are not a part of my mod, but i want to edit their behavior, i use that hook to give me an opportunity to add an event listener to each rabbit so that it will respond as the player consumes any food. Inside the callback i check to make sure the food eaten was a carrot and that the rabbit is within 5 tiles (20 distance units) of the player. In your code the contents of your start2() method should just be inside your fn() constructor above the 'return inst' line. At least i think so. I cant really what type of game object your 'volume' is supposed to be since honestly thats not a very good name for something meant to be a physical object. (ALL prefabs are meant to be physical in-game objects) It would be more helpful if you just zipped up your entire mod Link to comment Share on other sites More sharing options...
EmielRegis Posted February 19, 2014 Author Share Posted February 19, 2014 . Link to comment Share on other sites More sharing options...
EmielRegis Posted February 19, 2014 Author Share Posted February 19, 2014 you use the prefab post init callbacks in order to hook in to when things are spawned in game. It gives you an opportunity to edit those objects the moment they are created. Its a call that belongs in your modmain.lua file in the root folder of your mod so in your case that would mean mods/dysk/modmain.lua If you are creating your own prefab (volume.lua) then you wouldnt need to also use that hook. You are writing the entire file so you would just initialize it how you want. In my example since rabbits are not a part of my mod, but i want to edit their behavior, i use that hook to give me an opportunity to add an event listener to each rabbit so that it will respond as the player consumes any food. Inside the callback i check to make sure the food eaten was a carrot and that the rabbit is within 5 tiles (20 distance units) of the player. In your code the contents of your start2() method should just be inside your fn() constructor above the 'return inst' line. At least i think so. I cant really what type of game object your 'volume' is supposed to be since honestly thats not a very good name for something meant to be a physical object. (ALL prefabs are meant to be physical in-game objects) It would be more helpful if you just zipped up your entire modMy mod is simple, contains just that two prefabs that i trying to "link" ingame.f.zip Link to comment Share on other sites More sharing options...
seronis Posted February 20, 2014 Share Posted February 20, 2014 My mod is simple, contains just that two prefabs that i trying to "link" ingame.thats not a mod. those are 2 random files. zip it up properly please. ie: complete with folder structure in tact and with your modmain.lua, modinfo.lua etc Link to comment Share on other sites More sharing options...
EmielRegis Posted February 20, 2014 Author Share Posted February 20, 2014 thats not a mod. those are 2 random files. zip it up properly please. ie: complete with folder structure in tact and with your modmain.lua, modinfo.lua etcAs you wish. So basicly its 2 mods and they need to be turned on in menu at once to work (its big becouse it needs .fsb file) http://www30.zippyshare.com/v/38312202/file.html Link to comment Share on other sites More sharing options...
EmielRegis Posted February 22, 2014 Author Share Posted February 22, 2014 Anyone? Link to comment Share on other sites More sharing options...
JackSlender Posted February 24, 2014 Share Posted February 24, 2014 I'm not positive, but I THINK that the problem is that ListenForEvent is called in a function, rather then when you initialize it. Try doing this: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")endlocal 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:ListenForEvent("start", start) return inst end return Prefab("common/inventory/volume", fn, assets, prefabs)Tell me if that doesn't work, and I'll try to help more. Link to comment Share on other sites More sharing options...
EmielRegis Posted February 24, 2014 Author Share Posted February 24, 2014 I'm not positive, but I THINK that the problem is that ListenForEvent is called in a function, rather then when you initialize it. Try doing this: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")endlocal 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:ListenForEvent("start", start) return inst end return Prefab("common/inventory/volume", fn, assets, prefabs)Tell me if that doesn't work, and I'll try to help more.Thx, It was not exactly that, but helped me figure it out anyway. One more question: Is there any file with SoundEmmiter functions? I want just know what functions are available and how to use them. Link to comment Share on other sites More sharing options...
EmielRegis Posted February 24, 2014 Author Share Posted February 24, 2014 I'm not positive, but I THINK that the problem is that ListenForEvent is called in a function, rather then when you initialize it. Try doing this: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")endlocal 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:ListenForEvent("start", start) return inst end return Prefab("common/inventory/volume", fn, assets, prefabs)Tell me if that doesn't work, and I'll try to help more.This is crazy... Its not working again. I tryied what you sended but it saying that "musicbox" is undeclared. Link to comment Share on other sites More sharing options...
JackSlender Posted February 24, 2014 Share Posted February 24, 2014 Ah yes, my mistake. You need to change this: inst.musicbox:ListenForEvent("start", start) to this: inst:ListenForEvent("start", start) That will hopefully help. Tell me if it doesn't, and I'll be happy to assist. Link to comment Share on other sites More sharing options...
seronis Posted February 25, 2014 Share Posted February 25, 2014 just remember its responder:ListenForEvent( "event_name", callback_name ); responder should be the object that will supplied as the first argument to callback_name method. Since your method is of the format local function start( randomname ) { --method body-- } the variable 'randomname' will be the same as 'responder'. So if you use 'inst' as the responder in fn() start() will be called with that instance as the argument and your sound emmiter call will act on that object. Does that make sense? Its why when you used 'inst.musicbox' as the responder the compiler gave you an error. You never create a musicbox reference anywhere in fn() so inst.musicbox would be equal to 'nil' and not be valid Link to comment Share on other sites More sharing options...
EmielRegis Posted February 25, 2014 Author Share Posted February 25, 2014 Ah yes, my mistake. You need to change this: inst.musicbox:ListenForEvent("start", start) to this: inst:ListenForEvent("start", start) That will hopefully help. Tell me if it doesn't, and I'll be happy to assist.not working 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_bank70.fsb"), Asset("ATLAS", "images/inventoryimages/record.xml"), Asset("IMAGE", "images/inventoryimages/record.tex"),}prefabs = {}local function Start(inst) inst.SoundEmitter:PlaySound(inst.song, "dream") inst:Remove() end local function Off(inst) inst.SoundEmitter:KillSound("dream") inst:Remove() 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.song="tut07/musicbox/dream" inst:ListenForEvent("start", Start) inst:ListenForEvent("off", Off) return inst endreturn Prefab("common/inventory/volume", fn, assets, prefabs) Link to comment Share on other sites More sharing options...
JackSlender Posted February 25, 2014 Share Posted February 25, 2014 Can you post your error? Link to comment Share on other sites More sharing options...
seronis Posted February 25, 2014 Share Posted February 25, 2014 Why do you want your music player to self destruct as soon as someone tries to start or stop it ? Link to comment Share on other sites More sharing options...
EmielRegis Posted February 25, 2014 Author Share Posted February 25, 2014 Why do you want your music player to self destruct as soon as someone tries to start or stop it ?To test if this even work. Currently its just ignoring that function...Can you post your error?There is no error, its just not working as it should. Link to comment Share on other sites More sharing options...
JackSlender Posted February 25, 2014 Share Posted February 25, 2014 What is it doing? Sorry for asking soo much, but I need to know what the problem is to fix it. Link to comment Share on other sites More sharing options...
EmielRegis Posted February 25, 2014 Author Share Posted February 25, 2014 What is it doing? Sorry for asking soo much, but I need to know what the problem is to fix it. It should receive "start" or "off" event from "musicbox" prefab and then execute start or stop function. Here is musicbox code:local assets = { Asset("ANIM", "anim/phonograph.zip"), Asset("ATLAS", "images/inventoryimages/musicbox.xml"), Asset("IMAGE", "images/inventoryimages/musicbox.tex"), }local function play(inst) if inst.components.container:IsEmpty() == false then inst.AnimState:PlayAnimation("play_loop", true) inst:PushEvent("start") inst.SoundEmitter:PlaySound("tut07/musicbox/dream", "loop") endendlocal function stop(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end") inst:PushEvent("off") endlocal function itemtest(inst, item, slot) if item:HasTag("volume") then return true end return falseendlocal slotpos = {}table.insert(slotpos, Vector3(0, 0, 0))local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() -- MakeObstaclePhysics(inst, 0.1) MakeInventoryPhysics(inst) anim:SetBank("phonograph") anim:SetBuild("phonograph") anim:PlayAnimation("idle") inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("container") inst.components.container.itemtestfn = itemtest inst.components.container:SetNumSlots(1) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetanimbank = "ui_chest_3x3" inst.components.container.widgetanimbuild = "ui_chest_3x3" inst.components.container.widgetpos = Vector3(200,0,0) inst.components.container.side_align_tip = 100 inst.components.container.widgetbuttoninfo = widgetbuttoninfo inst.components.container.acceptsstacks = false inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("inspectable") inst:AddComponent("machine") inst.components.machine.turnonfn = play inst.components.machine.turnofffn = stop inst.components.machine.cooldowntime = 0 inst:AddTag("musicbox") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "musicbox" inst.components.inventoryitem.atlasname = "images/inventoryimages/musicbox.xml" return instend--[[local crafting_recipe = Recipe("musicbox", {Ingredient("boards", 4),Ingredient("goldnugget", 2), RECIPETABS.FARM, TECH.SCIENCE_ONE, "pickle_barrel_placer")crafting_recipe.atlas = "images/inventoryimages/pickle_barrel.xml"]]return Prefab( "common/musicbox", fn, assets, nil) Link to comment Share on other sites More sharing options...
JackSlender Posted February 25, 2014 Share Posted February 25, 2014 Okay, try this for volume: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_bank70.fsb"), Asset("ATLAS", "images/inventoryimages/record.xml"), Asset("IMAGE", "images/inventoryimages/record.tex"),}prefabs = {} local function Start(inst) inst.SoundEmitter:PlaySound(inst.song, "dream") inst:Remove() end local function Off(inst) inst.SoundEmitter:KillSound("dream") inst:Remove()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.song="tut07/musicbox/dream" inst.musicbox = TheSim:FindFirstEntityWithTag("musicbox") inst:ListenForEvent("start", function() Start(inst) end, inst.musicbox) inst:ListenForEvent("off", function() Off(inst) end, inst.musicbox) return inst endreturn Prefab("common/inventory/volume", fn, assets, prefabs)and this for musicbox:local assets ={ Asset("ANIM", "anim/phonograph.zip"), Asset("ATLAS", "images/inventoryimages/musicbox.xml"), Asset("IMAGE", "images/inventoryimages/musicbox.tex"), } local function play(inst) if inst.components.container:IsEmpty() == false then inst.AnimState:PlayAnimation("play_loop", true) inst.SoundEmitter:PlaySound("tut07/musicbox/dream", "loop") inst:PushEvent("start") endend local function stop(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end") inst.SoundEmitter:KillSound("loop") inst:PushEvent("off")end local function itemtest(inst, item, slot) if item:HasTag("volume") then return true end return falseend local slotpos = {}table.insert(slotpos, Vector3(0, 0, 0))local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() -- MakeObstaclePhysics(inst, 0.1) MakeInventoryPhysics(inst) anim:SetBank("phonograph") anim:SetBuild("phonograph") anim:PlayAnimation("idle") inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("container") inst.components.container.itemtestfn = itemtest inst.components.container:SetNumSlots(1) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetanimbank = "ui_chest_3x3" inst.components.container.widgetanimbuild = "ui_chest_3x3" inst.components.container.widgetpos = Vector3(200,0,0) inst.components.container.side_align_tip = 100 inst.components.container.widgetbuttoninfo = widgetbuttoninfo inst.components.container.acceptsstacks = false inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("inspectable") inst:AddComponent("machine") inst.components.machine.turnonfn = play inst.components.machine.turnofffn = stop inst.components.machine.cooldowntime = 0 inst:AddTag("musicbox") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "musicbox" inst.components.inventoryitem.atlasname = "images/inventoryimages/musicbox.xml" return instend --[[local crafting_recipe = Recipe("musicbox", {Ingredient("boards", 4),Ingredient("goldnugget", 2), RECIPETABS.FARM, TECH.SCIENCE_ONE, "pickle_barrel_placer")crafting_recipe.atlas = "images/inventoryimages/pickle_barrel.xml"]] return Prefab( "common/musicbox", fn, assets, nil)I think that the container will give you an error too because you don't define widgetbuttoninfo, but you'll have to see. Link to comment Share on other sites More sharing options...
EmielRegis Posted February 25, 2014 Author Share Posted February 25, 2014 Okay, try this for volume: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_bank70.fsb"), Asset("ATLAS", "images/inventoryimages/record.xml"), Asset("IMAGE", "images/inventoryimages/record.tex"),}prefabs = {} local function Start(inst) inst.SoundEmitter:PlaySound(inst.song, "dream") inst:Remove() end local function Off(inst) inst.SoundEmitter:KillSound("dream") inst:Remove()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.song="tut07/musicbox/dream" inst.musicbox = TheSim:FindFirstEntityWithTag("musicbox") inst:ListenForEvent("start", function() Start(inst) end, inst.musicbox) inst:ListenForEvent("off", function() Off(inst) end, inst.musicbox) return inst endreturn Prefab("common/inventory/volume", fn, assets, prefabs)and this for musicbox:local assets ={ Asset("ANIM", "anim/phonograph.zip"), Asset("ATLAS", "images/inventoryimages/musicbox.xml"), Asset("IMAGE", "images/inventoryimages/musicbox.tex"), } local function play(inst) if inst.components.container:IsEmpty() == false then inst.AnimState:PlayAnimation("play_loop", true) inst.SoundEmitter:PlaySound("tut07/musicbox/dream", "loop") inst:PushEvent("start") endend local function stop(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end") inst.SoundEmitter:KillSound("loop") inst:PushEvent("off")end local function itemtest(inst, item, slot) if item:HasTag("volume") then return true end return falseend local slotpos = {}table.insert(slotpos, Vector3(0, 0, 0))local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() -- MakeObstaclePhysics(inst, 0.1) MakeInventoryPhysics(inst) anim:SetBank("phonograph") anim:SetBuild("phonograph") anim:PlayAnimation("idle") inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("container") inst.components.container.itemtestfn = itemtest inst.components.container:SetNumSlots(1) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetanimbank = "ui_chest_3x3" inst.components.container.widgetanimbuild = "ui_chest_3x3" inst.components.container.widgetpos = Vector3(200,0,0) inst.components.container.side_align_tip = 100 inst.components.container.widgetbuttoninfo = widgetbuttoninfo inst.components.container.acceptsstacks = false inst.songToPlay = "tut07/musicbox/dream" inst:AddComponent("inspectable") inst:AddComponent("machine") inst.components.machine.turnonfn = play inst.components.machine.turnofffn = stop inst.components.machine.cooldowntime = 0 inst:AddTag("musicbox") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "musicbox" inst.components.inventoryitem.atlasname = "images/inventoryimages/musicbox.xml" return instend --[[local crafting_recipe = Recipe("musicbox", {Ingredient("boards", 4),Ingredient("goldnugget", 2), RECIPETABS.FARM, TECH.SCIENCE_ONE, "pickle_barrel_placer")crafting_recipe.atlas = "images/inventoryimages/pickle_barrel.xml"]] return Prefab( "common/musicbox", fn, assets, nil)I think that the container will give you an error too because you don't define widgetbuttoninfo, but you'll have to see.I just deleted that whole widget stuff, but functions in volume are still ignored Why that events won't work? Link to comment Share on other sites More sharing options...
JackSlender Posted February 25, 2014 Share Posted February 25, 2014 Are you sure they are not working, or is it just playing the same song from both classes? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.