Jump to content

Can I use RemapSoundEvent outside of modmain?


Recommended Posts

Simple enough question here, is there some way I can use RemapSoundEvent outside of modmain? I want to be able to play a different sound than normal that's played when frozen, but since that's part of the stategraphs, I can't easily replace it. I figured out I could do this with the use of RemapSoundEvent, but I only want it to take effect for the split second I actually use the different sound effect, after I want it to return to normal.

I tried using

RemapSoundEvent( "dontstarve/common/freezecreature", "icestomp/sound/activate" )

but it threw an error, saying RemapSoundEvent is not declared. Do I need to require something at the beginning of my prefab code?

Link to comment
Share on other sites

At the chance to land myself in doo-doo for bad coding practice

Two ways I can think of, off the top of my head:

1. Pass the function from modmain (variables/parameters can be functions )

ie:

local myFunction = function(parameter)
    -- some code
end

myFunction(enterParameter)

is totally valid

so is

local myFunction = function(parameter)
    -- some code
end

local anotherFunction = function()
    -- some code
end

myFunction(anotherFunction)

2. Find where RemapSoundEvent is declared by text searching accross all files in /scripts/

In this case, it seems to be on

TheSim:RemapSoundEvent(name, new_name)

TheSim is a C-side object (userdata), and sits on GLOBAL.

I'm not 100% sure, but for my imported class, GLOBAL become my new normal environment.

so, I think there's a 50/50 shot that this would work:

TheSim:RemapSoundEvent( "dontstarve/common/freezecreature", "icestomp/sound/activate" )

 

Note: I haven't considered in-depth the problem you're having. I'm only responding to the title more or less.

There may be a better solution to your actual problem.

Edited by Bigfootmech
  • Like 1
Link to comment
Share on other sites

For other functions, look at modutil.lua, this file contains the default sandbox environment for all modmain files.

	env.RemapSoundEvent = function(name, new_name)
		initprint("RemapSoundEvent", name, new_name)
		TheSim:RemapSoundEvent(name, new_name)
	end

For example on seeing how the remap works.

  • Like 2
Link to comment
Share on other sites

18 hours ago, Bigfootmech said:

Note: I haven't considered in-depth the problem you're having. I'm only responding to the title more or less.

There may be a better solution to your actual problem.

I know I closed this already, but I do know a better way I could do this, which would be to make my own state I could go to whenever the actions happens, which negates the original sound entirely, but that's too hard lol, an this works.

Link to comment
Share on other sites

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
 Share

×
  • Create New...