Re: question for better inventory system in bgt

For the example you gave, you might do something like this:

if(fish>0) res.add_item_tts("fishes ... you own "+fish+" hit enter to examine");
if(salmon>0) res.add_item_tts("salmons ... you own "+salmon+" hit enter to examine");
if(grain>0) res.add_item_tts("grane ... you own "+grane+" hit enter to examine");
if(flour>0) res.add_item_tts("flour ... you own "+flour+" hit enter to examine");
res.add_item_tts("turn back");

But that, too, is quite clunky. Also, you would need to use the get_item_name method of the dynamic menu, since the item count can change.
You could go object-oriented, or dictionaries, or parallel arrays, and keep track of descriptions, names, and counts outside of the inventory function. The advantage to this is that you can then use loops to build your menus, and adding new items becomes much easier.
(It'd be nice if BGT dictionaries supported the indexing operator. It's situations like these that make me miss _javascript_.)

Example using dictionaries:

dictionary resources, descs;

int get_resource(string name) {
if(resources.exists(name)==false) return 0;
int ret;
resources.get(name, ret);
return ret;
}

// function for adding to resources; returns the current value:
void add_resource(string name, int count=1) {
int value=get_resource(name);
resources.set(name, value+count);
return value+count;
}


// Part of the inventory function:
void inventory() {
// ... 
// Resources:
string[] keys=resources.get_keys();
for(uint i=0; i<keys.length(); i++) {
int count=get_resource(keys[i]);
if(count<=0) continue;
res.add_item_tts(keys[i] + ", you have " + count + "; hit enter to examine.", keys[i]);
}

res.add_item_tts("Turn back", "back");

menu_result=res.run("This is your menu for resources", true);

string name=res.get_item_name(menu_result);

// You might be better off ordering these differently, but this is the simplest for just getting descriptions:
if(name!="back") {
string desc="A " + name + ", no description available.";
if(descs.exists(name)) descs.get(name, desc);
voice.speak_interrupt(desc);
}

// Etc...

}

HTH

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : pelantas via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : pelantas via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : brian . kurosawa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : pelantas via Audiogames-reflector

Reply via email to