Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support
randomize timer
x = int (rnd * 4) +1
If x = 1 then PlaySound GetPath (4) + "music1.mp3", 0,9
If x = 2 then PlaySound GetPath (4) + "music2.mp3", 0,9
If x = 3 then PlaySound GetPath (4) + "music3.mp3", 0,9
If x = 4 then PlaySound GetPath (4) + "music4.mp3", 0,9
randomize timer
x = int (rnd * 4) +1
PlaySound GetPath (4) + "music" + x + ".mp3", 0,9
It's a good solution but you could take advantage of the fact that you used the random number in the filename!
reneuend wrote:It's a good solution but you could take advantage of the fact that you used the random number in the filename!
- Code: Select all
randomize timer
x = int (rnd * 4) +1
PlaySound GetPath (4) + "music" + x + ".mp3", 0,9
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySoundWin7 GetPath(4) + "SVS Theme Song.mp3", 0, 9
else
PlaySoundWin7 GetPath(4) + "Battle Song.mp3", 0, 9
end if
Function RandomInt(lower,upper)
Randomize
RandomInt = int(rnd*(upper-lower+1))+lower
End Function 'RandomInt
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySoundWin7 GetPath(4) + "SVS Theme Song.mp3", 0, 9
'NOTE: if not using AM4.6 use the following instead!
PlaySound2 GetPath(4) + "SVS Theme Song.mp3", 9, 0
else
PlaySoundWin7 GetPath(4) + "Battle Song.mp3", 0, 9
'NOTE: if not using AM4.6 use the following instead!
PlaySound2 GetPath(4) + "Battle Song.mp3", 9, 0
end if
Sub PlaySoundWin7(SoundFile, NumRepeat, ChannelNumber)
If ChannelNumber < 9 Then
'With VBScript it is currently not possible to interact with the 8 first audio channels.
MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
Exit Sub
End If
If Action.IsComponentInstalled("NSPlay.NSPlayCtl.1") = False Then
MsgBox "Unable to find the media player component.", vbCritical, "Error"
Else
If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = false Then
AddComponent "NSPlay.NSPlayCtl.1", "MediaPlayer" + CStr(ChannelNumber)
End If
Component("MediaPlayer" + CStr(ChannelNumber)).Object.FileName = SoundFile
Component("MediaPlayer" + CStr(ChannelNumber)).Object.PlayCount = NumRepeat
Component("MediaPlayer" + CStr(ChannelNumber)).Object.Play
End If
End Sub
Sub PlaySound2(FileName, Channel, Repeat)
'PlaySound "c:\filename.mp3", False
'If the sound file is located in your "Areas" folder, use the "GetPath(4)" command:
'PlaySound GetPath(4) + "c:\filename.mp3", False
'To Stop a sound: StopSound
Action.LoadControl MediaPlayerObject(Channel)
MediaPlayerObject(Channel).FileName = FileName
If Repeat = True Then
MediaPlayerObject(Channel).PlayCount = 0
Else
MediaPlayerObject(Channel).PlayCount = 1
End If
MediaPlayerObject(Channel).Play
End Sub
Sub randomsongs
randomize
rndnum = int(RND * 2)+1
If rndnum=1 Then
PlaySound GetPath(4) + "SVS Theme Song.mp3", False
End If
If rndnum=2 Then
PlaySound GetPath(4) + "Battle Song.mp3", False
End If
End Sub
Action.CreateTimedEvent 1, "randomsongs", True
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySound2 GetPath(4) + "SVS Theme Song.mp3", 9, 0
else
PlaySound2 GetPath(4) + "Battle Song.mp3", 9, 0
end if
Morsy wrote:
- Code: Select all
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySound2 GetPath(4) + "SVS Theme Song.mp3", 9, 0
else
PlaySound2 GetPath(4) + "Battle Song.mp3", 9, 0
end if
I put this in the Advanced tab of the frame properties, put the songs in the areas folder, and test the frame.
What I get in return is an error message that says "Type mismatch "PlaySound2". D:
Morsy wrote:
- Code: Select all
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySound2 GetPath(4) + "SVS Theme Song.mp3", 9, 0
else
PlaySound2 GetPath(4) + "Battle Song.mp3", 9, 0
end if
I put this in the Advanced tab of the frame properties, put the songs in the areas folder, and test the frame.
What I get in return is an error message that says "Type mismatch "PlaySound2". D:
Sub PlaySound2(FileName, Channel, Repeat)
'PlaySound "c:\filename.mp3", False
'If the sound file is located in your "Areas" folder, use the "GetPath(4)" command:
'PlaySound GetPath(4) + "c:\filename.mp3", False
'To Stop a sound: StopSound
Action.LoadControl MediaPlayerObject(Channel)
MediaPlayerObject(Channel).FileName = FileName
If Repeat = True Then
MediaPlayerObject(Channel).PlayCount = 0
Else
MediaPlayerObject(Channel).PlayCount = 1
End If
MediaPlayerObject(Channel).Play
End Sub
Function RandomInt(lower,upper)
Randomize
RandomInt = int(rnd*(upper-lower+1))+lower
End Function 'RandomInt
Sub PlaySound2(FileName, Channel, Repeat)
PlaySound GetPath(4) + "c:\filename.mp3", False
Action.LoadControl MediaPlayerObject(Channel)
MediaPlayerObject(Channel).FileName = FileName
If Repeat = True Then
MediaPlayerObject(Channel).PlayCount = 0
Else
MediaPlayerObject(Channel).PlayCount = 1
End If
MediaPlayerObject(Channel).Play
End Sub
Function RandomInt(lower,upper)
Randomize
RandomInt = int(rnd*(upper-lower+1))+lower
End Function 'RandomInt
rnd_play = RandomInt(1,2)
if rnd_play = 1 then
PlaySound2 GetPath(4) + "SVS Theme Song.mp3", 9, 0
else
PlaySound2 GetPath(4) + "Battle Song.mp3", 9, 0
end if
Function RandomInt(lower,upper)
Randomize
RandomInt = int(rnd*(upper-lower+1))+lower
End Function 'RandomInt
Sub PlaySoundWin7(SoundFile, NumRepeat, ChannelNumber)
If ChannelNumber < 9 Then
'With VBScript it is currently not possible to interact with the 8 first audio channels.
MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
Exit Sub
End If
If Action.IsComponentInstalled("NSPlay.NSPlayCtl.1") = False Then
MsgBox "Unable to find the media player component.", vbCritical, "Error"
Else
If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = false Then
AddComponent "NSPlay.NSPlayCtl.1", "MediaPlayer" + CStr(ChannelNumber)
End If
Component("MediaPlayer" + CStr(ChannelNumber)).Object.FileName = SoundFile
Component("MediaPlayer" + CStr(ChannelNumber)).Object.PlayCount = NumRepeat
Component("MediaPlayer" + CStr(ChannelNumber)).Object.Play
End If
End Sub
randomize
rnd_play = int( RND * 4 ) + 1
If rnd_play = 1 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD 1.mp3", 0, 9
End If
If rnd_play = 2 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD 2.mp3", 0, 9
End If
If rnd_play = 3 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD 3.mp3", 0, 9
End If
If rnd_play = 4 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD 4.mp3", 0, 9
End If
Select Case (rnd_play)
Case 1:
Case 2:
Case 3:
Case 4:
End Select
If rnd_play > 0 And rnd_play <= 4 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD" + rnd_play + ".mp3", 0, 9
Else
'Do something here where rnd_play is what is expected
End
reneuend wrote:You could also use the Select statement, which can be better when there are several IFs:
- Code: Select all
Select Case (rnd_play)
Case 1:
Case 2:
Case 3:
Case 4:
End Select
or even better in this case, just replace the character in the string with rnd_play:
- Code: Select all
If rnd_play > 0 And rnd_play <= 4 Then
PlaySoundWin7 GetPath(4) + "GMOD GMOD" + rnd_play + ".mp3", 0, 9
Else
'Do something here where rnd_play is what is expected
End
Return to Adventure Maker Technical Support and Bug Reports
Users browsing this forum: No registered users and 0 guests