Page 1 of 1
Need help, NOW!!
Posted:
Wed Sep 28, 2005 12:46 am
by Game A Gogo
When I press the space bar, I want to play a sound, but variating to 3 sound, I dont want to make the player always to do the same sound when hes jumping.
Posted:
Wed Sep 28, 2005 1:09 am
by willg101
Use this code on key down:
- Code: Select all
myvar=rand(3)
if (myvar=1)PlaySound("my_sound_1", 1.000000, 1, 0.000000);
if (myvar=2)PlaySound("my_sound_2", 1.000000, 1, 0.000000);
if (myvar=3)PlaySound("my_sound_3", 1.000000, 1, 0.000000);
If you want a random noise, that is. Otherwise, use this, which will play three sounds in "order":
- Code: Select all
if (myvar=1)PlaySound("my_sound_1", 1.000000, 1, 0.000000);
if (myvar=2)PlaySound("my_sound_2", 1.000000, 1, 0.000000);
if (myvar=3)PlaySound("my_sound_3", 1.000000, 1, 0.000000);
myvar++;
if (myvar=4) myvar=1;
HTHs
[Edit: Feel free to correct my code if it's incorrect, anyone]
Posted:
Wed Sep 28, 2005 2:07 am
by makslane
Don't use if(myvar=1) .... //put the 1 in myvar
Use: if(myvar == 1) ... //Compares myvar to 1
Posted:
Wed Sep 28, 2005 8:10 pm
by Game A Gogo
I alredy knew that Makslane, but tanx anyway...
Posted:
Wed Sep 28, 2005 10:21 pm
by willg101
makslane wrote:Don't use if(myvar=1) .... //put the 1 in myvar
Use: if(myvar == 1) ... //Compares myvar to 1
Huh? What's this do differently? I didn't have any problems when I tested it...
Thanks for helping, I am really trying to learn better script!
Posted:
Wed Sep 28, 2005 11:57 pm
by Fuzzy
When you use if (var == 1) you are telling GE to check if var is equal to one. When you do (var = 1) you are telling GE to make var equal to one. It might work, but it might leave you with a nasty bug...
Posted:
Wed Sep 28, 2005 11:57 pm
by Game A Gogo
its because when you use '=' it normaly does nothing, its like its going to set something to a number, but ant because of "if(" and ")"
so I greatly recemend to use ' =='.
Posted:
Thu Sep 29, 2005 12:12 am
by Joshua Worth
I know a bit about it, I read a C++ manual(but I couldn't be bothered finishing it
)