View previous topic :: View next topic |
Author |
Message |
FIRESKY Cheater Reputation: 0
Joined: 01 Mar 2017 Posts: 34
|
Posted: Sun Apr 28, 2024 12:06 pm Post subject: Combo Box Lua (Goal: Same Index Selection No Sound) |
|
|
Hey guys, I was pondering a solution where:
1) I select a command line from the example combo box:
index == 2 then: -- > PLAY A SOUND
2) If I select "the same" command line from the ComboBox = this time i not want a SOUND WILL BE PLAYED AGAIN (Obviously until I change the selection from the combo box).
Ultimately the objective is to play a sound only if I select a different command line from the combo box,
obviously if from INDEX 2 I go back to INDEX 1 the sound must be played at least the first time from the selection
SCRIPT: Currently with this example obviously the sound is ok on the first selection but then it is disabled permanently... because something is needed to restore it if I change the selection index.
sound = 0
function CEComboBox1OnSelect(sender)
index = combobox_getItemIndex(CEtrainer_CTComboBox1);
if index == -1 then return end;
if index == 1 then
writeInteger("BLA BLA",tonumber("1"))
if sound == 0 then
playSound( findTableFile('music.wav') )
sound = 1
end
elseif index == 2 then
writeInteger("BLA BLA",tonumber("2"))
if sound == 0 then
playSound( findTableFile('music.wav') )
sound = 1
end
end
end
setMethodProperty(CEtrainer_CTComboBox1, "OnSelect", CEComboBox1OnSelect)
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 34
Joined: 16 Feb 2017 Posts: 1418
|
Posted: Sun Apr 28, 2024 12:58 pm Post subject: |
|
|
Code: | if frm1 then frm1.Destroy() frm1=nil end
frm1=createForm()
CEtrainer = {}
CEtrainer.CTComboBox1=createComboBox(frm1)
CEtrainer.CTComboBox1.Left=50
CEtrainer.CTComboBox1.Top=50
CEtrainer.CTComboBox1.ReadOnly=true
CEtrainer.CTComboBox1.Style='csDropDownList'
CEtrainer.CTComboBox1.Items.Add("select index")
CEtrainer.CTComboBox1.Items.Add("index 1")
CEtrainer.CTComboBox1.Items.Add("index 2")
CEtrainer.CTComboBox1.Items.Add("index 3")
CEtrainer.CTComboBox1.Items.Add("index 4")
CEtrainer.CTComboBox1.ItemIndex=0
local sound = 0
local sound2 = 0
CEtrainer.CTComboBox1.OnChange=function()
index = combobox_getItemIndex(CEtrainer_CTComboBox1);
if sound2==index then sound=1 else sound=0 end
if index==1 then
if sound==0 then
print("play sound")
sound=1
sound2=index
else
print("No play sound!")
end
elseif index==2 then
if sound==0 then
print("play sound")
sound=1
sound2=index
else
print("No play sound!")
end
elseif index==3 then
if sound==0 then
print("play sound")
sound=1
sound2=index
else
print("No play sound!")
end
elseif index==4 then
if sound==0 then
print("play sound")
sound=1
sound2=index
else
print("No play sound!")
end
end
end |
-- your code:
Code: | local sound = 0
local sound2 = 0
CEtrainer.CTComboBox1.OnChange=function()
index = combobox_getItemIndex(CEtrainer_CTComboBox1);
if sound2==index then sound=1 else sound=0 end
if index==1 then
if sound==0 then
writeInteger("BLA BLA",tonumber("1"))
playSound( findTableFile('music.wav'))
sound=1
sound2=index
else
writeInteger("BLA BLA",tonumber("1"))
end
elseif index==2 then
if sound==0 then
writeInteger("BLA BLA",tonumber("2"))
playSound( findTableFile('music.wav'))
sound=1
sound2=index
else
writeInteger("BLA BLA",tonumber("2"))
end
end
end |
_________________
|
|
Back to top |
|
|
FIRESKY Cheater Reputation: 0
Joined: 01 Mar 2017 Posts: 34
|
Posted: Sun Apr 28, 2024 10:24 pm Post subject: |
|
|
Hey AylinCE,
thanks for your time, honestly I had thought of something similar with a double sound that recalled the state of the index, excellent tip, I hope to be able to reciprocate in the future.
|
|
Back to top |
|
|
|