Author Topic: Playing random music during fights  (Read 4714 times)

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Playing random music during fights
« on: April 06, 2016, 11:30:13 PM »
I have 12 tracks for the Battlebots arena, but I have to switch each track around one by one. Is there a way to get the game to select a track randomly without having to quit the game every time I need to change tracks?

Offline Clickbeetle

  • *
  • Posts: 3375
  • Rep: 21
  • In Soviet Russia, bugs stomp YOU!
  • Awards BOTM Winner
    • View Profile
    • Beetle Bros site
    • Awards
Re: Playing random music during fights
« Reply #1 on: April 08, 2016, 10:59:15 PM »
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)

To lack feeling is to be dead, but to act on every feeling is to be a child.
-Brandon Sanderson, The Way of Kings

Offline Serge

  • *
  • Posts: 1530
  • Rep: 13
    • View Profile
    • http://www.q3k.org/
    • Awards
Re: Playing random music during fights
« Reply #2 on: May 01, 2016, 12:13:07 PM »
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)

You can make this a little bit less ugly like so (untested):

Code: [Select]
sounds = ["Sounds/track1.wav", "Sounds/track2.wav", "Sounds/track3.wav"] # etc...
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or:

Code: [Select]
sounds = ["Sounds/track%i.wav" % i for i in range(1, 12+1)]
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or even:

Code: [Select]
sound = "Sounds/track%i.wav" % random.randint(1, 12)
self.AddSound = plus.CreateSound(sound, False, (0,0,0))
plus.loopSound(self.AddSound)

(does AddSound even have to be a object variable? if not, just call it plus_sound or something...)
home | twitter | yt | gmf de/compiler | component freedom | xmpp: q3k@q3k.org | email: q3k@q3k.org

Offline R01

  • Heavyweight
  • Posts: 769
  • Rep: 1
  • Awards BOTM Winner
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #3 on: May 01, 2016, 12:44:41 PM »
Is it possible/is this already for having different tracks for each arena(by adding it to each of their own init scripts)?
Tournament History:
Showcases:
https://gametechmods.com/forums/index.php?topic=18882.0
https://gametechmods.com/forums/index.php?topic=19197.0

Offline cephalopod

Re: Playing random music during fights
« Reply #4 on: May 01, 2016, 02:27:51 PM »
Each arena already has it's own music edited through the py's.
eg

(From the RW Live arena in RWRA2)
bristol bot builders / two headed death flamingo / snappy robots
//
kindest and friendliest '13, '15, '16, '17 / favourite staff member '14, '15

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #5 on: May 03, 2016, 08:40:44 PM »
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)

You can make this a little bit less ugly like so (untested):

Code: [Select]
sounds = ["Sounds/track1.wav", "Sounds/track2.wav", "Sounds/track3.wav"] # etc...
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or:

Code: [Select]
sounds = ["Sounds/track%i.wav" % i for i in range(1, 12+1)]
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or even:

Code: [Select]
sound = "Sounds/track%i.wav" % random.randint(1, 12)
self.AddSound = plus.CreateSound(sound, False, (0,0,0))
plus.loopSound(self.AddSound)

(does AddSound even have to be a object variable? if not, just call it plus_sound or something...)

Where exactly do I put these codes? Do they have to be placed in a certain spot?

Offline Naryar

  • Posts: 23278
  • Rep: 20
  • hybrids oui oui
    • http://www.youtube.com/us
  • Awards BOTM Winner
    • View Profile
    • Awards
  • Skype: TheMightyNaryar
Re: Playing random music during fights
« Reply #6 on: May 04, 2016, 09:50:23 AM »
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #7 on: May 04, 2016, 06:20:17 PM »
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
I know that, but I'm wondering if I have to put the code in a certain place in the file.

Offline Serge

  • *
  • Posts: 1530
  • Rep: 13
    • View Profile
    • http://www.q3k.org/
    • Awards
Re: Playing random music during fights
« Reply #8 on: May 04, 2016, 06:21:57 PM »
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
I know that, but I'm wondering if I have to put the code in a certain place in the file.

If you have to ask this question, you should probably learn some Python. It's a useful life skill, and you won't have to be handholded (handheld? handoldered? you get my point.) by others in the future.
home | twitter | yt | gmf de/compiler | component freedom | xmpp: q3k@q3k.org | email: q3k@q3k.org

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #9 on: May 12, 2016, 09:16:58 PM »
Anyone?

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #10 on: May 12, 2016, 10:32:52 PM »
Clickbeetle already told you where to paste his code in the file and Serge's code is just a replacement for the code that Clickbeetle posted. In other words, you put it in the same place.

Paste this in def __init__, making sure "import random" is at the very top of the py.

Assuming that you don't insert it in the middle of something, there are no additional requirements regarding placement.

Offline Serge

  • *
  • Posts: 1530
  • Rep: 13
    • View Profile
    • http://www.q3k.org/
    • Awards
Re: Playing random music during fights
« Reply #11 on: May 13, 2016, 04:55:11 AM »
Anyone?
Why are you ignoring my advice?
home | twitter | yt | gmf de/compiler | component freedom | xmpp: q3k@q3k.org | email: q3k@q3k.org

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #12 on: May 13, 2016, 07:16:00 PM »
Anyone?
Why are you ignoring my advice?
I did not ignore your advice. I tried to learn this myself & it is way too complicated. TBH, I'd rather have someone who has the knowledge try to help me with this than waste a lot of my life trying to learn all this stuff that I have no experience doing.

Offline cephalopod

Re: Playing random music during fights
« Reply #13 on: May 13, 2016, 07:48:10 PM »
Perhaps you should ask for an alternate solution instead of seemingly ignoring everyone that has 'wasted their life' giving you solutions...
bristol bot builders / two headed death flamingo / snappy robots
//
kindest and friendliest '13, '15, '16, '17 / favourite staff member '14, '15

Offline Battlebotsboy

  • Antweight
  • Posts: 46
  • Rep: -1
  • When sparks fly, robots die!
    • https://www.facebook.com/
    • https://www.youtube.com/u
    • View Profile
    • Awards
Re: Playing random music during fights
« Reply #14 on: May 13, 2016, 08:41:27 PM »
Perhaps you should ask for an alternate solution instead of seemingly ignoring everyone that has 'wasted their life' giving you solutions...
I'm sorry, I did what I could, but it's all too confusing for me. And I'm not ignoring everyone, I've done everything everyone suggested & nothing worked. I don't know if I'm doing something wrong or what.