Jump to content

Custom sound option


AggrorJorn
 Share

Recommended Posts

I am making this alarm thingoid were you pick your own sound. Sound file plays in a loop but every time you open the properties window, the sound start playing in another track (so the sound file is playing twice at the same time).

 

require("scripts/class")

local class=CreateClass(...)

--Create the Rotation speed tab and property
function class:InitDialog(grid)
self.super:InitDialog(grid)
alarmTab = grid:AddGroup("Alarm")
alarmTab:AddProperty("alarmsound", PROPERTY_FILE,"Wav Files (*.wav):wav;Ogg Vorbis (*.ogg):ogg", "Alarm Sound")
alarmTab:Expand(1)
end

--Create the object as soon as it is dragged in to the editor
function class:CreateObject(model)
local object=self.super:CreateObject(model)

--when property values are changed in the property layout, you need to apply them with SetKey()
function object:SetKey(key,value)
	--the alarmsound key gets a new value (or path) assigned.
	if key=="alarmsound" then
		self.alarmsound = value
	end

	return 1
end

--use the values from the 'keys' to do things in the scene.
function object:GetKey(key,value)

	if key=="alarmsound" then
		if self.alarmsound ~= nil then
			soundFile = LoadSound("abstract::"..self.alarmsound)
			self.model:EmitSound(soundFile,8,1,1)
		end
	end

	return value
end

       end

end

Link to comment
Share on other sites

thanks for the answer Macklebee.

 

This 'Unlocking' thing, does that occur everytime when you open the properties menu for a model?

 

Here are the stages of how the object scripts work with the normal class/object functions:

1) Placing the model into the scene for the first time:

  • Creating class whatever
  • Creates the object
  • Gets the Keys
  • Sets the Keys
  • Unlocks the Keys

2) Opening the model's property dialog:

  • Adds the properties to dialog
  • Gets the Keys

3) Pressing the APPLY button in the property dialog:

  • Gets the Keys
  • Sets the Keys
  • Unlocks the Keys

4) Deleting the model from the scene:

  • Freeing class whatever

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...