Page 1 of 4

Sound script

Posted: Wed Sep 12, 2012 10:50 pm
by LordGarth
Hello I need help in what to put exactly in for a sound to play.

How do I exactly define the sound in the folder and I am using a pressure plate connected to a script entity. I have tried many ways and the farthest I got was "warning no sample" was shown on the preview screen when i walked over the pressure plate.

Please advise on exact scripting needed in each area.

I have the sound wave file in the sound folder as well.

My script in the sound folder is this.

defineSound{

name = "scream1",

filename = "scream1.wav",

loop = "false",

volume = "0.5",

minDistance = "30",

maxDistance = "32",
}

script entity is
function playsound()
playSound("SCREAM1")

end
Thx,

LordGarth

Re: Sound script

Posted: Wed Sep 12, 2012 11:03 pm
by antti
I can spot two issues:
The filename parameter needs the folders too, like so:

Code: Select all

filename = "mod_assets/sounds/scream1.wav",
And the script entity's name does not match the sample definition since it should be case sensitive. So just switch "SCREAM1" to "scream1" in the script entity. Let us know how it goes.

Re: Sound script

Posted: Wed Sep 12, 2012 11:17 pm
by LordGarth
still shows no sample

sound script

defineSound = {
name = "scream1",
filename = "mod_assets\sounds\scream1.wav",
loop = "false",
volume = "0.5",
minDistance = "30",
maxDistance = "32",
}

entityscript

function playsound()
playSound("scream1")

end

I tried caps and regular and tried both slash types in the filepath

LordGarth

Re: Sound script

Posted: Wed Sep 12, 2012 11:31 pm
by antti
Oh, I spotted an issue. You need to remove the quotation marks around loop, volume, minDistance and maxDistance values. Quotation marks indicate a string (a piece of text) but the datatypes we need in these fields are numbers and a boolean (true/false). This is a little programmerly but what this essentially means is that we were trying to pass of a text that literally read "32" when the engine was expecting a number with the value of 32.

And yeah, forward slashes ( / ) should be used in the folders.

Let's hope it works this time :)

Re: Sound script

Posted: Wed Sep 12, 2012 11:42 pm
by LordGarth
nope still says no sample

is the entity script correct

function playsound()
playSound("scream1")

end

Re: Sound script

Posted: Wed Sep 12, 2012 11:57 pm
by antti
I'm not completely sure if it affects this but there's an unnecessary equals-to sign after defineSound. Try to remove it.
So, this should be what you have in your sounds.lua:

Code: Select all

defineSound{
name = "scream1",
filename = "mod_assets/sounds/scream1.wav",
loop = false,
volume = 0.5,
minDistance = 30,
maxDistance = 32,
}
The script entity looks good to me. You can see if it works by trying to play an existing sound like playSound("level_up")

Oh, and I forgot probably the most significant thing when testing this :(... The .lua files in your mod_assets folder will be loaded only when loading the project. So any time you modify something there, reopen the project in dungeon editor to refresh the changes in the lua files.

I'll have to check if I remembered to mention this in the modding documents, it's rather essential :P

Edit: I'll have to get some more sleep now, I'll check this thread out in the morning.

Re: Sound script

Posted: Thu Sep 13, 2012 1:31 pm
by Xzalander
Hi, I thought it would be better to keep related issues in the same thread. Just wondering why I'm getting an error here as I have no experience at all with LUA. i'm just going by the scripting tutorials you've provided.

Code: Select all

function pullLever()
	if combinationLever1:getLeverState() == "activated" and
	combinationLever2:getLeverState() == "activated" then
		combinationDoor:open()
		playSound(secret)
	else
		combinationDoor:close()
	end
end
It is my understanding that the Predefined sounds, don't need any clarification other than the keyword, but I get the error "Bad argument #1 to 'playSound' (string expected, got nil)".

Any help would be great.

Re: Sound script

Posted: Thu Sep 13, 2012 1:39 pm
by antti
Ah, that's simple. You need quotation marks in playSound("secret") since a string is expected there.

Re: Sound script

Posted: Thu Sep 13, 2012 1:41 pm
by petri
playSound expects a string parameter so you have to quote the sound name -> playSound("secret")
EDIT: oops, Antti beat me :lol:

Re: Sound script

Posted: Thu Sep 13, 2012 1:50 pm
by Xzalander
Oh well that is deflating :p Haha. Does that pply for other pre-defineds as well then, such as the particle systems?