Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, dBc), 18,430 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Play wav file #122784
04/10/07 19:45
04/10/07 19:45
Joined: Oct 2000
Posts: 113
L
Lawrence Offline OP
Member
Lawrence  Offline OP
Member
L

Joined: Oct 2000
Posts: 113
Hi All,

I would like to write a script that will allow the player to walk up to a statue and a wav file plays, walks away and it stops playing. Walk up to it again and it will play the wav again. I am using ver 6.405.

Thanks,

Lawrence

Re: Play wav file [Re: Lawrence] #122785
04/10/07 19:58
04/10/07 19:58

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Code:

sound snd_hello = <hello_player.wav>; // your wav (adjust)

action statue {
var lv_snd_dist = 100; // 100 quants for play (adjust)
var lv_snd_flag = off; // sound played

// wait for player...
while(player==null){wait(1);}

// statue loop
while(1){
// play when approaching
if(vec_dist(player.x,my.x)<lv_snd_dist && lv_snd_flag==off){
snd_play(snd_hello, 100, 0); // play the sound
lv_snd_flag=on; // play not again until player is gone...
}else{
lv_snd_flag=off; // ready to play again...
}
wait(1);
}
}




or if it should loop...

[EDIT]
Code:

sound snd_hello = <hello_player.wav>; // your wav (adjust)

action statue {
var lv_snd_dist = 100; // 100 quants for play (adjust)
var lv_snd_hdl; // sound handle

// wait for player...
while(player==null){wait(1);}

// statue loop
while(1){
// play when approaching
if(vec_dist(player.x,my.x)<lv_snd_dist && !snd_playing(lv_snd_hdl)){
lv_snd_hdl=snd_loop(snd_hello, 100, 0); // play the sound
}

// stop loop
if(vec_dist(player.x,my.x)>lv_snd_dist && snd_playing(lv_snd_hdl)){
snd_stop(lv_snd_hdl);
}
wait(1);
}
}


[/EDIT]

not tested but should work...

mercuryus

Last edited by mercuryus; 04/10/07 20:05.
Re: Play wav file [Re: ] #122786
04/11/07 17:25
04/11/07 17:25
Joined: Oct 2000
Posts: 113
L
Lawrence Offline OP
Member
Lawrence  Offline OP
Member
L

Joined: Oct 2000
Posts: 113
Thanks mercuryus,

I tried the code and attached my model to the action but it did not start a wav file. I am not sure why not.

Can you tell why you have while(player==null)?

Lawrence

Re: Play wav file [Re: Lawrence] #122787
04/11/07 17:32
04/11/07 17:32
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Because he uses the entity pointer "player" to check the distance.
If he would not "wait for the player" through using that while loop [which can also be written as while(!player)] you might get an empty pointer error.

Re: Play wav file [Re: Xarthor] #122788
04/11/07 17:35
04/11/07 17:35
Joined: Oct 2000
Posts: 113
L
Lawrence Offline OP
Member
Lawrence  Offline OP
Member
L

Joined: Oct 2000
Posts: 113
Thunder,

That explains alot. Why do you not have to do the same for the my pointer?

Lawrence

Re: Play wav file [Re: Lawrence] #122789
04/11/07 17:39
04/11/07 17:39
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
The my pointer automaticly refers to the entity which uses it.
Imagine a bird (dumb example I know), when he is born he instantly knows who he is. (well kind of)

But when the engine loads the level it might happen that the statue entity is created _before_ the player and thus does its action start to run earlier.
Now on the first frame cycle there might be no player, so trying to access the player pointer (which is not set yet) will maybe create an "empty pointer error" (thats because that pointer is empty )

Hope this explains the thing a bit, still I have no idea why the code does not work for you.

- Do you have an entity which call itself "player" ?

Re: Play wav file [Re: Xarthor] #122790
04/11/07 17:46
04/11/07 17:46
Joined: Oct 2000
Posts: 113
L
Lawrence Offline OP
Member
Lawrence  Offline OP
Member
L

Joined: Oct 2000
Posts: 113
Thanks Thunder,

That really helps.

The only code I have is the template code for A6, 1st camera and biped to walk, nothing else. I am not getting any errors or anything. I thought maybe the distance might be a problem, it is not a very big level(I am just using it for testing this code) I set the distance to 50 and then 25 from 100. This did not help. I have tried different wav files, that to did not help.

Lawrence

Re: Play wav file [Re: Lawrence] #122791
04/11/07 17:50
04/11/07 17:50
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Ok .. no the problem is actually that there will be no player pointer.
So your code will never enter that "real" while loop.
It will wait forever

I'm not sure but the pointer plbiped01 should refer to your player model:
Code:

sound snd_hello = <hello_player.wav>; // your wav (adjust)

action statue {
var lv_snd_dist = 100; // 100 quants for play (adjust)
var lv_snd_hdl; // sound handle

// wait for player...
while(plbiped01==null){wait(1);}

// statue loop
while(1){
// play when approaching
if(vec_dist(plbiped01.x,my.x)<lv_snd_dist && !snd_playing(lv_snd_hdl)){
lv_snd_hdl=snd_loop(snd_hello, 100, 0); // play the sound
}

// stop loop
if(vec_dist(plbiped01.x,my.x)>lv_snd_dist && snd_playing(lv_snd_hdl)){
snd_stop(lv_snd_hdl);
}
wait(1);
}
}


Not sure though, as I have never worked with the A6 templates.

EDIT:
It might also be just PLBIPED

Last edited by Thunder; 04/11/07 17:56.
Re: Play wav file [Re: Xarthor] #122792
04/11/07 17:57
04/11/07 17:57
Joined: Oct 2000
Posts: 113
L
Lawrence Offline OP
Member
Lawrence  Offline OP
Member
L

Joined: Oct 2000
Posts: 113
Using plbiped01 does not work. It comes up with errors.

Is there a way to set player to my player model cbabe_mdl_000? I wonder if this what is needed?

Lawrence

Re: Play wav file [Re: Lawrence] #122793
04/11/07 17:59
04/11/07 17:59
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Take a look at my last post, I edited it, you may try plbiped
(without the 01 behind it)

Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1