|
Post by MonstaWolf on Dec 2, 2015 16:03:43 GMT
Didn't know where exactly to put this.
I'm trying to write a script that simply iObjectRefreshes a soundeffect to a random file off a list when the sound ends. I can write that, but the one part I'm having trouble is making 3D Rad detect when a sound ends. I've tried messing with valueprints in a way that when the sound ends (not in 'looping' mode obviously) but the number will always stay the same even when it ends, whether it's detecting the volume or the pitch.
Is there any way that 3D Rad can detect when a sound ends?
|
|
|
Post by Power Supersport on Dec 2, 2015 19:09:06 GMT
Unfortunately, I've never needed that... I didn't encounter any possibility for detecting the end of the sound...
Maybe put a constant time number...
|
|
|
Post by MonstaWolf on Dec 7, 2015 13:11:37 GMT
What is a constant time number? Sorry noob question
|
|
|
Post by F1Andre on Dec 7, 2015 13:25:46 GMT
I'm not sure if this is what Power is trying to say, but if you know how long the sound effect is you can start a timer and when the timer reaches a certain value you can continue with what you want to do after that.
|
|
|
Post by MonstaWolf on Dec 7, 2015 16:05:24 GMT
I'm not sure if this is what Power is trying to say, but if you know how long the sound effect is you can start a timer and when the timer reaches a certain value you can continue with what you want to do after that. Well, I'm trying to have a somewhat decent library of music in my game. I want it to be that when a song ends, the script uses iObjectRefresh to choose a random song. I can do the random song part, but I'm having trouble making the script know when to activate. I'll try a few different things, see how they work out
|
|
|
Post by F1Andre on Dec 7, 2015 17:57:30 GMT
Do something similar like what I have said above. Use a array to store the exact (I would make this time 1 second longer than it actually is) length in seconds that the song is and use a integer as a index to get the right time. So when you choose a random song, that song should have a integer value corresponding to the time allocated in the array and once that song is chosen you must get the value (time) in that array.
Here is a code snippet to help you understand it better:
int[] songTime = new int[] {93, 205, 180, 155};
int songIndex = 0;
// Now you would calculate the time that has passed from the moment you started playing the song and we will call that variable "timePass" // You must have a corresponding integer value of the songIndex and the song that must be played. It must also correspond to the value in the array.
if(timePass >= songTime[songIndex]) { // Now you would stop the song and play the next one. // Remember to change the songIndex to match the song again and just repeat a similar process like the one above } I have forgotten how you declare a array in Angel script so please correct me if it's wrong (it most likely is).
If you have any questions please feel free to ask.
Thanks
--Andre
|
|
|
Post by MonstaWolf on Dec 8, 2015 13:09:29 GMT
Well, you know a lot more than me when it comes to scripting I'm kind-of noobish at it. I could probably figure it out if I spent enough time with it, but my new question is: would it be possible to use that with a randomizer? I don't want the songs to go in a certain order each time you start up the game, as that would get boring or annoying. (Also, I know this may sound dumb, but could you please tell me what an array is? Thanks I'm trying my best to learn.)
|
|
|
Post by F1Andre on Dec 8, 2015 14:22:36 GMT
First tell me how you are calculate a random number and then we will take it from there. If it is via script, post the script.
|
|
|
Post by MonstaWolf on Dec 8, 2015 15:34:34 GMT
I haven't actually written it yet, as I was first trying to figure out how the game would detect it first (But we have that somewhat cleared up already). I was probably going to use iFloatRand to choose which iObjectRefresh (song) would start.
|
|
|
Post by F1Andre on Dec 8, 2015 17:13:18 GMT
Okay, so you can get a random float from 0 to the amount of songs there are and round it of to the nearest integer value (float car = 0.1f; int car2 = car). I can only help you further once you present some code.
An array is something you should look up, it is something best heard and learnt from a novice programmer (I'm talking real advanced, they tend to know the right terminology). What I would suggest for new person entering the world of programming for the first time via game development, is to learn a language such as Java or C sharp (these are the easiest ones and allow you to port and change between different languages since the syntax are quite universal). Spend at least 2 months worth of time developing and learning that language (I prefer a book as it covers a lot more with a much greater depth into certain elements). If you were with unity you could get a book right of the back that teaches you everything from scratch...unfortunately 3D rad doesn't offer you books like this. I wouldn't encourage you to port to UNITY unless you get the basics (even more) down.
As I always say to people, learn a language like Java and develop software, now stop developing software and program game logic. Now after 5 months has pasted on, move back to software dev and make a simple program like a calculator (no UI). Then, and only then, will you appreciate the programming of game logic.
|
|
|
Post by MonstaWolf on Dec 8, 2015 21:17:27 GMT
Thanks for the help. I will begin to write the script and get back to you when it's functional, to a point.
|
|
|
Post by MonstaWolf on Dec 8, 2015 22:36:30 GMT
Okay, so, I'm trying to make a script to randomly choose between two files when I press a button, but it keeps telling me that it expected an expression value at 9,14 and 10,14. Could you please check it out? I'm logging out for the night by the way so I will be able to talk again tomorrow float random;
void Main()
{
if(iKeyDown(iKeyCode("DIK_L"))){
//Songs
Song[1] = \\objects\SoundEffect\data\Fourward_-_Elektrik.ogg;
Song[2] = \\objects\SoundEffect\data\The_toxic_avenger_-_Escape_bloody_beetroots_remix.ogg;
//I'm using a key input to activate it for now
random=iFloatRand(0,2);
iObjectRefresh(OBJ_0, Song[random]);
}
}
|
|
|
Post by F1Andre on Dec 8, 2015 23:25:40 GMT
You have to convert the float to an integer value: int randomNew = random;. Just put that piece after you get a random number. Than you want to create an array of strings to store the file paths. Also you haven't closed your if statement. Just make sure your filepaths are correct and that you use the iObjectRefresh correctly, other than that everything looks good (Remember that a pc starts counting at 0).
float random;
void Main()
{
if(iKeyDown(iKeyCode("DIK_L"))){
//Songs string[] song = {"\\objects\SoundEffect\data\Fourward_-_Elektrik.ogg", "\\objects\SoundEffect\data\The_toxic_avenger_-_Escape_bloody_beetroots_remix.ogg"}; // Create an array of strings
//Song[1] = <a href="file://\\objects\SoundEffect\data\Fourward_-_Elektrik.ogg">\\objects\SoundEffect\data\Fourward_-_Elektrik.ogg</a>; //This is wrong
//Song[2] = <a href="file://\\objects\SoundEffect\data\The_toxic_avenger_-_Escape_bloody_beetroots_remix.ogg">\\objects\SoundEffect\data\The_toxic_avenger_-_Escape_bloody_beetroots_remix.ogg</a>; // This is wrong
//I'm using a key input to activate it for now
random = iFloatRand(0,1); // Remember that a computer also starts counting at zero, so the first string the array that has been created above is actually 0 and the second 1, I'm sure you get the picture. So you want this value between 0 and 1
int newRandom = random; // Convert float to nearest integer value
iObjectRefresh(OBJ_0, song[newRandom]); // Refresh your object
} }
|
|
|
Post by MonstaWolf on Dec 9, 2015 12:56:54 GMT
Thanks a ton, this will certainly help. I see where I went wrong now, and will certainly use this as a reference for the future. I read the script over to make sure I understand it, and I certainly do. I'm probably going to use a randomizer for many things throughout the game, and I will always look back at this for reference. I hope you know how much I appreciate this Would you like to request a song to be in the game? If you do, I'd prefer it to be a fast-paced one.
|
|
|
Post by F1Andre on Dec 9, 2015 13:05:58 GMT
No problem Monsta, let us know if the script works when tend to use it. You should select the songs yourself, it's your own game and requires your own personal touch. Thank you for the offer.
|
|
|
Post by MonstaWolf on Dec 9, 2015 13:07:54 GMT
No problem I have one question though. When I press the correct key, the sound just cuts out. Do I need \\3drad_res in the filepath?
|
|
|
Post by F1Andre on Dec 9, 2015 14:06:29 GMT
To be honest, I am not sure. Haven't really worked with file paths before. Power or GameDev may be able to help you out there.
Sorry for that. But does the sound actually play or is there nothing?
|
|
|
Post by MonstaWolf on Dec 9, 2015 14:20:23 GMT
If I select the file manually in the SoundEffect settings, it plays each time I start it. But when I press L, it stops the music. After that, if I start the game, it won't play the music until I manually reselect the song again in the SoundEffect settings. Do you have any idea, or should I contact one of them?
|
|
|
Post by F1Andre on Dec 9, 2015 14:38:31 GMT
Okay so I know that your file path is wrong it should be: ".\\3DRad_res\\objects\\SoundEffect\\data\\Fourward_-_Elektrik.ogg". Remember to use double backslashes and that ful stop at the beginning. Fix the paths and try it now to see if it works.
|
|
|
Post by MonstaWolf on Dec 9, 2015 14:42:29 GMT
Ah ok, that would explain it. I was doing {.\\3DRad_res\objects\so on...} I'll try that when I get the chance.
|
|