2014-11-28 21:13:07

Всем программистам привет!
Такой вопрос:
когда играет заставка, как ее остановить, пробовал как в коде ниже, не получается!
вот код:
#include "dynamic_menu.bgt"

int player;
sound start;
sound vin;
sound ot;
sound sot;
sound end;
sound kill;
sound police;

void main()
{
ot.load("11.wav");
vin.load("vin.wav");
sot.load("121.wav");
end.load("end.wav");
kill.load("kill.wav");
police.load("police.wav");
start.load("start.wav");
tts_voice voice;
dynamic_menu menu;
menu.allow_escape = true;
menu.wrap = true;
menu.add_item_tts("Start game");
menu.add_item_tts("Exit game");
show_game_window("Quests");
voice.speak_wait("Welcome to Quests");
int choice;
do
{
choice = menu.run("Please choose a menu item with the arrow keys, then hit enter to activate it.", true);
if(choice==1)
{
game_play();
}
}
while(choice!=0 and choice!=2);
voice.speak_wait("Thanks for playing.");
}

void game_play()
{
while(true)
{
start.play_wait();
if(start.playing==true and key_pressed(KEY_RETURN))
{
start.stop();
}
start.close();
sot.play_wait();
sot.close();
if(key_pressed(KEY_SPACE))
{
player=random(1, 2);
}
if(player==1)
{
vin.play();
kill.play();
end.play();
}
else if(player==2)
{
ot.play_wait();
ot.close();
main();
}
}
}

2014-11-29 16:42:14

You haven't given us enough information to be able to help you. You've indicated that there's a problem, but not what you're trying to accomplish.
For starters, play_wait is probably not what you want. It plays the audio and stops the program dead until the audio finishes playing. Your key_pressed check won't work for this reason.
Also, you really don't want to be calling main from within your game loop. The program has to keep a running log of all the functions that have been called, so when the latest function returns the one that called it can resume from the point at which it left off. This is called a call stack, and it has limited capacity (all though quite large).
If your loop calls main frequently for no apparent reason you may experience a runtime error after a while.
Otherwise, you should provide more information about what it is you're trying to do and the specific problems you're having.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.

2014-11-30 19:21:46

Will the engine even let you call main that way? It's incredibly bad form to do so, so I havent' ever tried something like that. Aside from issues with stack overflow, imagine that you have some kind of game intro sequence. This would be started by your main function, so you'd hear that sequence every time main was called. As an end-user, I'd be concerned that there was a bug and that the game was somehow reloading itself for no reason.

Best Regards,
Hayden

2014-11-30 22:39:32

Yeah, you can call main like that. If you learn about recursive functions, calling main can actually be useful. But I have a feeling this guy isn't even close to learning about that stuff.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2014-11-30 23:59:53

I wholeheartedly disagree that recursive calling of main is good. If you want something recursively called, deligate that to another function would be my philosophy here. Like I said, main tends to supervise any number of tasks when loading a program that you might not necessarily want to reoccur during execution.

Best Regards,
Hayden

2014-12-21 20:54:05

What I do is have a function for a menu and not have it in the main loop so when the game is over, I can just call it and the user can choose to start the game again or exit etc. Generally if you want to use things awften you should maybe have functions that do those things, not a bigger function that might do things you don't want it to do when you call it. Anyways, I hope that makes sense and that's just my oppinion