2019-09-07 15:49:58

Hey everyone!

I want ask that what's problem in my code?:

#include "sound_pool.bgt"
tts_voice v;

bool jatek=true;

sound money;

int m;

void main()
{
show_game_window("Hearing Money");
install_keyhook();
v.speak_interrupt("Hearing Money!");
while(true)
{
if(key_pressed(KEY_S))
{
v.speak_interrupt("Start");
game();
}
if(key_pressed(KEY_E))
{
exit();
}
}
}

void game()
{
sound_pool p;
while(jatek==true)
{
if(key_pressed(KEY_E))
{
p.destroy_all();
jatek==false;
main();
}
if(key_pressed(KEY_SPACE))
{
m=random(1,3);
if(m==1)
{
money.load("sounds/szazas.wav");
money.play();
wait(1400);
valaszt();
wait(1400);
}
if(m==2)
{
money.load("sounds/huszas.wav");
money.play();
wait(1400);
valaszt();
wait(1400);
}
if(m==3)
{
money.load("sounds/tizes.wav");
money.play();
wait(1400);
valaszt();
wait(1400);
}
}
}
}

void valaszt()
{
if(key_pressed(KEY_C))
{
v.speak_interrupt(+m);
}
sound select;
select.load("sounds/valaszt.wav");
select.play_wait();
if(m==1)
{
if(key_pressed(KEY_1))
{
v.speak_interrupt("siker!");
}
}
if(m==2)
{
if(key_pressed(KEY_2))
{
v.speak_interrupt("siker!");
}
}
if(m==3)
{
if(key_pressed(KEY_3))
{
v.speak_interrupt("siker!");
}
}
}

2019-09-07 17:23:46

what you ment was.
tts_voice voice;
not
tts_voice v;

I am a divine being. I can be called a primordial deity, but that might be pushing it, a smidge. I am the only one of my kind to have ten tails, with others having nine. I don't mean to sound arrogant, but I have ascended my own race.

2019-09-07 17:29:54

@2 that does not change anything.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-09-07 18:13:23 (edited by targor 2019-09-07 18:16:02)

You're calling the main function in your game function again. I haven't worked with BGT a long time, but I would say that isn't allowed because then you're practically starting your program a second time. But correct me if I'm wrong. What you want to do is: Replace the line "main();" in your game function with "return;". Then you're not entering main again, but continue where you left it earlier.

We are pleased, that you made it through the final challenge, where we pretended we were going to murder you. We are throwing a party in honor of your tremendous success. Place the device on the ground, then lay on your stomach with your arms at your sides. A party associate will arrive shortly to collect you for your party. Assume the party submission position or you will miss the party.

2019-09-07 18:34:22

The fact that I did not use the name voice instead of v is because the second one is shorter.I didn't write what my problem was. I have to press that key many times when the money falls and for some reason do not properly check whether it was correct or not.

2019-09-07 19:01:18

Few things here, although you didn't specified which key:
1. Line 37, I guess you meaned jatek=false?
2. You're missing a wait command in your loops. When you want to make an infinite loop for example to catch keys, you need to include call for wait on its end, because otherwise it'll drain cpu and that isn't healthy for hardware. smile
5 ms should work just fine, goal is just to prevent running full speed.
3. The valaszt function, although I didn't get what it should do checks for pressed keys, however only one time. That means, you need to hit exactly the moment where if (key_pressed(KEY_some)) is executed in the program, what is... impossible.
You can higher you chance by pressing the key more times, that's I guess what you meaned by the need to press keys repeatedly.
It's hard to tell the best solution, when I don't know, what is the program supposed to do, however one thing applies independently of purpose - when you're checking for a key press, it always should be looped.

Best regards

Rastislav

2019-09-17 16:18:49

Rastislav is right, you can never check for a key press without a loop. It doesn't work reliably. Besides, why do you check for 3 different key presses but always say the same thing, no matter which key was pressed? Couldn't that be simplified somehow? I think you may be trying to add some text to a number or something. But it's difficult to guess the purpose when it's a different language than English. What language is it, by the way, if I may ask? I'm curious. :-)
Lukas

I won't be using this account any more or participating in the forum activity through other childish means like creating an alternate account. I've asked for the account to be removed but I'm not sure if that's actually technically possible here. Just writing this for people to know that I won't be replying, posting new topics or checking private messages until the account is potentially removed.

2019-09-17 17:31:08

@4, it's possible. It's not recomended in some chases cause you are really just restarting the program. You can of course make some variables to tell the funktion what it shouldn't do again but it makes things just more complicated then they need to be.

Lamas with hats, but with sponge bob as carl Stay tuned.

https://www.youtube.com/channel/UCvAUQt … subscriber

2019-09-17 20:14:45

7, the language is hungarian.