Returning the result of a phrase

Hi everyone,

I’m embarking on a monstruous project where I’m attempting to remake a Pokemon game from the ground up in Inform 7. I recognise the immense scope of the project, but so far things are going well and I’m quite pleased with where I’ve got regarding randomly generating and calculating Pokemon stats. Below is the code I’m using to do so:

[ Spawning specific Pokémon]
To spawn a (T - some text) at level (L - a number) in (R - a room):
	let P be a random off-stage Pokémon;
	now P is in R;
	now the Level of P is L;
	apply basic information of T to P;
	apply random information to P;
	calculate stats of P;

[ Apply basic information (specific to a Pokémon species) ]
To apply basic information of (T - some text) to (P - a Pokémon):
	choose row with a Species of T in Table P1;
	now the Index of P is the Index entry;
	now the Species of P is the Species entry;
	now the printed name of P is the Species entry;
	now the Type1 of P is the Type1 entry;
	now the Type2 of P is the Type2 entry;
	now the Base HP of P is the B_HP entry;
	now the Base Atk of P is the B_Atk entry;
	now the Base Def of P is the B_Def entry;
	now the Base SpAtk of P is the B_SpAtk entry;
	now the Base SpDef of P is the B_SpDef entry;
	now the Base Spd of P is the B_Spd entry;
	
[ Apply random information (individual to every Pokémon) ]
To apply random information to (P - a Pokémon):
	now the Nat ID of P is a random number from 1 to 25;
	now the IV HP of P is a random number from 0 to 31;
	now the IV Atk of P is a random number from 0 to 31;
	now the IV Def of P is a random number from 0 to 31;
	now the IV SpAtk of P is a random number from 0 to 31;
	now the IV SpDef of P is a random number from 0 to 31;
	now the IV Spd of P is a random number from 0 to 31;
	
[ Perform stat calculations (must have applied basic and random information first) ]
To calculate stats of (P - a Pokémon):
	choose row Nat ID of P in Table P2;
	now the Nature of P is the Nature entry;
	now the Nat Atk of P is the N_Atk entry;
	now the Nat Def of P is the N_Def entry;
	now the Nat SpAtk of P is the N_SpAtk entry;
	now the Nat SpDef of P is the N_SpDef entry;
	now the Nat Spd of P is the N_Spd entry;
	now the Total HP of P is (((((2 * Base HP of P) + IV HP of P + (EV HP of P / 4)) * Level of P) / 100) + Level of P + 10);
	now the Total Atk of P is (((((((2 * Base Atk of P) + IV Atk of P + (EV Atk of P / 4)) * Level of P) / 100) + 5) * Nat Atk of P) / 10);
	now the Total Def of P is (((((((2 * Base Def of P) + IV Def of P + (EV Def of P / 4)) * Level of P) / 100) + 5) * Nat Def of P) / 10);
	now the Total SpAtk of P is (((((((2 * Base SpAtk of P) + IV SpAtk of P + (EV SpAtk of P / 4)) * Level of P) / 100) + 5) * Nat SpAtk of P) / 10);
	now the Total SpDef of P is (((((((2 * Base SpDef of P) + IV SpDef of P + (EV SpDef of P / 4)) * Level of P) / 100) + 5) * Nat SpDef of P) / 10);
	now the Total Spd of P is (((((((2 * Base Spd of P) + IV Spd of P + (EV Spd of P / 4)) * Level of P) / 100) + 5) * Nat Spd of P) / 10);

Now, here’s where I run into a problem. Currently I’ve got 100 Pokémon (a kind of animal) sitting offstage, and when I use this phrase to spawn one, it grabs one at random and moves it to the room I need it in. My issue is that I’m now not sure how to do anything with it. All of the Pokemon are just named “Pokemon”, so I can’t say something like “now the Pokemon is inside the Pokeball” because… which Pokemon?

What I’m looking for is a way for my spawning phrase to return the ID of the pokemon or something so that I can use it later. I’m happy to name my stockpile of offstage Pokemon all individually if need be, but I’m still not sure how to get the name of the Pokemon out of the phrase. Hoping someone can help me with that.

An I7 phrase that returns a value looks like:

To decide what Pokémon is the spawn of (T - some text) at level (L - a number) in (R - a room):
	let P be [...whatever...];
	decide on P.

Then you can write something like:

let P be the spawn of "foo" at level 4 in the Kitchen;

Ah! Thank you so much!
I knew it had something to do with “To decide”, but I just couldn’t find the right wording. This is a big help, thanks!

If, say, you wanted one object for each different type of Pokemon (and just bring the appropriate ones into play rather than dynamically swapping the same objects around), you might find this useful – you can create objects directly from a table. (This probably wouldn’t work if more than one of the same Pokemon type can be in the same place at the same time.)

Regarding populating “blank” offstage objects as needed, you might find this of interest, in particular the deck implementations.

Thnks Gavin,

I have looked into both of these kind of implementations. Ultimately, I’m pretty happy with the way I’m implementing the off-stage Pokémon. I’m planning only store the player’s Pokémon permanently - all other trainers’ and wild Pokémon will be generated as needed.

I’m considering looking for a way to save the player’s boxed Pokémon to an external file or somethingso that I don’t need to maintain an object for each one, but I’m not sure if that’s the best approach or not.