Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
snd_tune query #459178
04/26/16 08:09
04/26/16 08:09
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
I've nearly got everything working for a car racing game.

My only problem now is I am trying to get a revving sound from the engine when it is accelerating - otherwise using the same sound as just a rumble.

As a test, I am using the LMB. But, when I run the below I get "Script Crash Main", I press OK, it finishes loading and then the sound plays but does not adjust frequency to mimic acceleration.

Any ideas?

#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
#include <particles.c>

SOUND* engine_sound = "engine.ogg";

function mouse_leftsound()
{
snd_loop(engine_sound,100,0);
}

.............other code here


function main()
{

.............other code here

while (1)
{

.............other code here

if(mouse_left){
on_mouse_left = mouse_leftsound;
var freq = ++300;
snd_tune(mouse_leftsound,100,freq,0);
}

.............other code here

wait(1);
}
}

Re: snd_tune query [Re: tex] #459187
04/26/16 11:21
04/26/16 11:21
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi,

I dont know if this is the cause but this part looks suspicious:

Code:
while (1)
{
.............other code here
if(mouse_left){
on_mouse_left = mouse_leftsound;
var freq = ++300;
snd_tune(mouse_leftsound,100,freq,0);
}
.............other code here
wait(1);
}



Placing in a while loop on_mouse_left = mouse_leftsound; looks a bit weird I think. Second shouldn't var freq = ++300; be var freq += 300; ? (dont know if that really matters though)
Finally, snd_loop(engine_sound,100,0); has no handle, which you need for snd_tune I think. This last one is why I think you get the crash and your bug.

Last edited by Reconnoiter; 04/26/16 11:23.
Re: snd_tune query [Re: Reconnoiter] #459188
04/26/16 11:42
04/26/16 11:42
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
Thanks for the speedy feedback Reconnoiter.

I have progressed to the script below - which almost works.

It is already inside the main while loop - so should be ok.

Yes - I didn't need the "on_mouse_left = mouse_leftsound;" to trigger the snd

Yes, I needed a handle - now that is 'rev'.

What happens now is the sound starts on load - good - the LMB triggers a change in pitch - good - but on release of LMB the pitch stays the same - it should go back to the original!

Because I am using 'speed' to also drive the wheels of the car I don't really want to change that although I think I need an 'else' to set 'speed' back to zero...

SOUND* engine_sound = "engine.ogg";

var rev;
var freq;

function mouse_leftsound()
{
rev = snd_loop(engine_sound,100,0);
}

.............other code here


function main()
{

.............other code here


mouse_leftsound();

while (1)
{

var speed=0;

if(mouse_left)
{
speed+=1; //forward speed
}

.............other code here

freq = 200*speed;
snd_tune(rev,100,freq,0);

.............other code here

wait(1);
}
}

Re: snd_tune query [Re: tex] #459194
04/26/16 13:31
04/26/16 13:31
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
No problem, glad to help.

As for your current problem, try to store the original frequency in e.g. a global variable, than put an else after if(mouse_left) to restore the original frequency. So something like this:

var original_freq = whateverNumberYouWantHere;
....
....
if(mouse_left) //left mouse button pressed?
{
speed+=1; //forward speed
freq = 200*speed;
}
else freq = original_freq; //left mouse button NOT pressed
....
....

Could be I misinterpreted your question.

Last edited by Reconnoiter; 04/26/16 13:33.
Re: snd_tune query [Re: Reconnoiter] #459199
04/26/16 14:03
04/26/16 14:03
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
that totally worked!

not sure what you are like with PhysX but I have a post over there that hasn't got a response - re concave objects... You might have some ideas?

thanks laugh

Last edited by tex; 04/26/16 14:04.

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

Gamestudio download | chip programmers | 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