gametechmods
Robot Arena => Discussion => Topic started by: Battlebotsboy 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?
-
Paste this in def __init__, making sure "import random" is at the very top of the py.
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)
-
Paste this in def __init__, making sure "import random" is at the very top of the py.
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):
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:
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:
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...)
-
Is it possible/is this already for having different tracks for each arena(by adding it to each of their own init scripts)?
-
Each arena already has it's own music edited through the py's.
eg
(https://gametechmods.com/uploads/images/728652016-05-01 20_25_44-Cortana.png)
(From the RW Live arena in RWRA2)
-
Paste this in def __init__, making sure "import random" is at the very top of the py.
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):
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:
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:
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?
-
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
-
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.
-
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 (http://learnpythonthehardway.org/book/). 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.
-
Anyone?
-
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.
-
Anyone?
Why are you ignoring my advice?
-
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.
-
Perhaps you should ask for an alternate solution instead of seemingly ignoring everyone that has 'wasted their life' giving you solutions...
-
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.