2015-03-22 18:01:58

I'm working on what I hope will be a much larger game, but I'm having some issues. I've got a unit set on a 1000 by 1000 map, and I want my unit to be able to do a 360-degree scan of his surroundings to a distance of 10 units, but I'm not entirely sure how to code this out. I have the feeling that two for loops then checking the value of my array is something to do with it. Maybe something like
for(int x=playerx-10; x<=playerx+10; x++)
{
for(int y=playery-10; y<=playery+10; y++)
{
//values greater than 0 are what i use for my units
if(galaxy[x][y]>0) {
//code to add this unit to dynamic_menu goes here;
}
}
}
Does that sound about right? I'm still pretty shakey on programming in general, and with BGT in particular. Thanks for any thoughts.

AKA president731

2015-03-22 18:36:54

Yeah, pretty much. That's more or less exactly how the character view command in Sengoku Jidai works.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2015-03-22 18:42:07

*crosses his fingers* Thanks. Now I'm trying to take what I find in that scan and place it into a dynamic menu. Something tells me this could be very interesting! tongue

AKA president731

2015-03-22 23:08:20

Ok, I've come across a bit of a problem with the menus I'm working on. When the user starts up my game, they're plopped down in a list of the ships they're able to command, 5 in total. When the player arrows down and hits enter on the ship, it then brings up the correct captain menu thus far. However, when a person hits escape or the return to fleet (admiral's) menu item, it kicks them clean out of the game, and I can't figure out why. Here's the two functions:
void fleetmenu()
{
dynamic_menu admiral_menu;
admiral_menu.add_click_sound("sounds/menuclick.wav");
admiral_menu.add_enter_sound("sounds/federation_computer2.ogg");
admiral_menu.allow_escape = true;
admiral_menu.wrap = true;
admiral_menu.add_item_tts("Command Enterprise");
admiral_menu.add_item_tts("Command Lexington");
admiral_menu.add_item_tts("Command Defiant");
admiral_menu.add_item_tts("Command Hood");
admiral_menu.add_item_tts("Command Intrepid");
admiral_menu.add_item_tts("Quit game");
int shipchoice=admiral_menu.run_extended("Fleet Menu",true,1,true);
switch(shipchoice) {
case 1:
shipvalue=0;
commandmenu();
break;

case 2:
shipvalue=1;
commandmenu();
break;

case 3:
shipvalue=2;
commandmenu();
break;

case 4:
shipvalue=3;
commandmenu();
break;

case 5:
shipvalue=4;
commandmenu();
break;

case 6:
voice.speak_wait("Thank you for playing.");
exit();
}}

void commandmenu()
{
dynamic_menu captain_menu;
captain_menu.add_click_sound("sounds/menuclick.wav");
captain_menu.add_enter_sound("sounds/federation_computer2.ogg");
captain_menu.allow_escape = true;
captain_menu.wrap = true;
captain_menu.add_item_tts("Course");
captain_menu.add_item_tts("Warp Drive");
captain_menu.add_item_tts("Short-range scan");
captain_menu.add_item_tts("Long-range scan");
captain_menu.add_item_tts("Phasers");
captain_menu.add_item_tts("Photon Torpedos");
captain_menu.add_item_tts("Briefing");
captain_menu.add_item_tts("Return to Fleet Menu");
int orderchoice;
do
{
orderchoice = captain_menu.run(fed_shipname[shipvalue] + "Captain Menu", true);
if(orderchoice==1) {
voice.speak("not implemented");
//coursemenu(shipvalue);
}

else if(orderchoice==2) {
voice.speak("not implemented");
//speedmenu(shipvalue);
}

else if(orderchoice==3) {
voice.speak("not implemented");
//shortscan(shipvalue);
}

else if(orderchoice==4) {
voice.speak("not implemented");
//longscan(shipvalue);
}

else if(orderchoice==5) {
voice.speak("not implemented");
//phaserlock(shipvalue);
}

else if(orderchoice==6) {
voice.speak("not implemented");
//photonlock(shipvalue);
}

else if(orderchoice==7) {
voice.speak("not implemented");
//briefing(shipvalue);
}

else if(orderchoice==8) {
return;
}

}
while(orderchoice!=0 and orderchoice!=9);
return;
}
Afraid I'm not a very good programmer in any language. sad

AKA president731

2015-03-22 23:25:31

Remember that programs run from top to bottom (kind of, at least in functions anyway).
Your code is running the fleetmenu then commandmenu functions. Execution works something like this.
Running fleetmenu
Running commandmenu (while still in fleetmenu)

So you now have one function running as the previous one is running. When commandmenu stops running, then fleetmenu continues. Fleetmenu has nothing else to do, therefore it exits. Then I imagine this happens all the way back to the main function. When the main function ends, the program exits. I recommend using some form of while loop to prevent this at some level.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2015-03-23 01:31:36

Would something like the do.while loop I used in the commandmenu work fine for the fleetmenu as well? It seemed that the do.while loop I used was a bit clumsy, which was why I tried the switch-case on the other menu instead. Maybe I was being too clever by half. big_smile

AKA president731

2015-03-23 12:43:10

Good morning,

First of all, you can disable scape key for your menu changing this line:
admiral_menu.allow_escape = false;


And I think your second menu doesn't redirect the player to the first one. Try something like:
else if(orderchoice==8) {
fleetmenu();
}

When your second function returns, the game has no more instructions to follow, so It closes.

Hope this helps.

Thumbs up