Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, SBGuy, Petra, flink, 1 invisible), 699 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
snd_play on key press? #125351
04/21/07 00:32
04/21/07 00:32
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
This code I THOUGHT would play a sound when I hit the "j" key.

Instead, it plays at startup and if i do press the "j" key, the engine aborts with "acknex.exe has encountered a problem..."!

Is this not the right code for it?

Code:

on_j= smb_jump();

...

function smb_jump()
{
snd_play (jump_snd,100,0);
}



I already tried a while() loop, but all that does is play the sound every frame cycle, and that gets really annoying.

So, can anyone help?


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: snd_play on key press? [Re: MrCode] #125352
04/21/07 00:51
04/21/07 00:51
Joined: Oct 2003
Posts: 1,258
Virginia, USA
qwerty823 Offline
Senior Developer
qwerty823  Offline
Senior Developer

Joined: Oct 2003
Posts: 1,258
Virginia, USA
Quote:

This code I THOUGHT would play a sound when I hit the "j" key.

Instead, it plays at startup and if i do press the "j" key, the engine aborts with "acknex.exe has encountered a problem..."!

Is this not the right code for it?

Code:

on_j= smb_jump();

...

function smb_jump()
{
snd_play (jump_snd,100,0);
}



I already tried a while() loop, but all that does is play the sound every frame cycle, and that gets really annoying.

So, can anyone help?




Common mistake.

on_j = smb_jump(); // This *runs* the function smb_jump, and assigns its return to on_j

on_j = smb_jump; // This assigns the function itself to on_j


You want the second one.


Never argue with an idiot. They drag you down to their level then beat you with experience
Re: snd_play on key press? [Re: qwerty823] #125353
04/21/07 02:29
04/21/07 02:29
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Parameter unknown smb_jump. is there something else I'm missing?

Here's the whole Code:

var video_mode= 8;
var video_screen= 1;
var video_depth= 32;

var walk_speed;
var breath_speed;
var jump_speed;

string anim_wmb= <JumpDude.wmb>;

string keys_str= "Use the arrow keys to move around.";
string keys2_str= "Press the J key to jump.";
string keys3_str= "Press I to see these instructions again.";

sound jump_snd= <smb_jumpsmall.wav>;

bmap intro_pcx= "jdudeintro.pcx";

function main()
{
level_load (anim_wmb);
wait(3);
camera.x= -48;
camera.y= 334;
camera.z= 149;
camera.pan= 281;
camera.tilt= -48;
camera.roll= 0;
pan_fade();
txt_show();
show_again();
on_j= smb_jump;
}

action char_walk
{
my.fat= on;
my.narrow= on;
c_setminmax(my);
while(1)
{
if(key_cuu== on)
{
c_move(my,vector(0,6 * time_step,0),nullvector,glide);
ent_animate(my,"walk",walk_speed,anm_cycle);
walk_speed+= 7 * time_step;
}
else
{
ent_animate(my,"stand",breath_speed,anm_cycle);
breath_speed+= 3 * time_step;
}
if(key_cud== on)
{
c_move(my,vector(0,-6 * time_step,0),nullvector,glide);
ent_animate(my,"walk",walk_speed,anm_cycle);
walk_speed+= -7 * time_step;
}
if(key_cul== on)
{
my.pan+= 10 * time_step;
}
if(key_cur== on)
{
my.pan-= 10 * time_step;
}
if(key_j== on)
{
c_move(my,vector(0,0,15 * time_step),nullvector,glide);
ent_animate(my,"jump",jump_speed,anm_cycle);
jump_speed+= 14 * time_step;
}
else
{
c_move(my,vector(0,0,-15 * time_step),nullvector,glide);
}
wait(1);
}
}

panel intro
{
pos_x= 0;
pos_y= 0;
bmap= intro_pcx;
flags= transparent, overlay, visible;
alpha= 100;
}

font big_fnt= "Times New Roman",1,20;

text keys_txt
{
pos_x= 384;
pos_y= 550;
font= big_fnt;
string= keys_str;
}

function pan_fade()
{
wait(-2);
while(1)
{
intro.alpha-= 3 * time_step;
wait(1);
}
}

function txt_show()
{
wait(-3);
keys_txt.visible= on;
wait(-3);
keys_txt.string= keys2_str;
wait(-3);
keys_txt.string= keys3_str;
wait(-3);
keys_txt.visible= off;
}

function show_again()
{
while(1)
{
if(key_i== on)
{
keys_txt.visible= on;
wait(1);
keys_txt.string= keys_str;
wait(-3);
keys_txt.string= keys2_str;
wait(-3);
keys_txt.string= keys3_str;
wait(-3);
keys_txt.visible= off;
}
wait(1);
}
}

function smb_jump()
{
snd_play(jump_snd,100,0);
}




Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: snd_play on key press? [Re: MrCode] #125354
04/21/07 02:46
04/21/07 02:46
Joined: Oct 2003
Posts: 702
Z
zazang Offline
User
zazang  Offline
User
Z

Joined: Oct 2003
Posts: 702
anywhere above the main function,just define a function prototype liek this :-

function smb_jump();

that shud fix it !

Re: snd_play on key press? [Re: zazang] #125355
04/21/07 03:15
04/21/07 03:15
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Duh! I should have known! it was trying to call the function that doesn't exist until after that line!


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: snd_play on key press? [Re: MrCode] #125356
04/21/07 03:19
04/21/07 03:19
Joined: Oct 2003
Posts: 702
Z
zazang Offline
User
zazang  Offline
User
Z

Joined: Oct 2003
Posts: 702
I make worse mistakes than this


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