Is HiEv's UInv a good choice for this usecase? If so, could you roughely walk me through process?

Twine Version: 2 online
Story Format: SC 2.31

Good morning, everybody!

I am working on prototype for a game which promotes team diversity: At the beginning, player can choose 6 out of 12 randomly generated co-workers (different in age, qualification, sex, origin, languages, etc), and then sends a subset of these 6 NPC into different missions.

I was wondering, if HiEv’s UInv could save me a lot of work, but I figured I ask for advice before starting to code.

According to logic of inventory systems, hiring process at the start would be a “shop”, and selected/bought npcs would constitute team / go into bag.

Can this work?

If yes, could you help me on how generation of npc on random basis? NPC should have different names, ages, qualifications, origins etc. So I thought I pick random information from arrays in StoryInit, e.g.:

<<set $formalEducation to ["vocational", "elementary", "secondary", "bachelor", "master", "phd"]>>
<<set $origin to ["USA", "France", "Germany", "UK", "Russia"]>>
<<set $usMaleNames to ["James","John","Robert","Linda","William","David","Richard","Joseph","Thomas","Charles"]>>
<<set $usFemaleNames to ["Mary","Patricia","Jennifer","Linda","Elizabeth","Barbara","Susan","Jessica","Sarah","Karen"]>>
<<set $usSurnames to ["SMITH","JOHNSON","WILLIAMS","BROWN","DAVIS","MILLER","WILSON","MOORE","TAYLOR","ANDERSON","THOMAS","JACKSON"]>>
// more arrays for other origins, languages, etc

Can I create NPCs on random basis with UInv?

Thank you

You don’t say what you’re doing with those co-workers after they’re generated, but from what you have said it sounds like UInv would be overkill for something like that. If you’re also planning on having various inventories (for the players, NPCs, rooms, etc.) then UInv would be good choice for that.

If you’re not using UInv, then you probably should just create an array of generic objects instead, with each array element being a generic object describing each co-worker. Something like:

<<set $workerList = []>>  /* Initialize array */
<<for _i = 0; _i < 12; _i++>>
	<<set _tempWorker = {}>>  /* Initialize generic object */
	<<set _tempWorker.education = $formalEducation.random()>>
	<<set _tempWorker.origin = $origin.random()>>
...etc...
	<<set $workerList.push(_tempWorker)>>  /* Add object to the end of the array */
<</for>>

That will create an array of twelve co-worker objects within the $workerList array, which the player can pick from. Once they’ve picked, you can delete the ones from that array which were’t chosen by the player (make sure you do it in reverse order using the .deleteAt() method, from 11 down to 0, otherwise the indexes of the later elements will be incorrect when you get to deleting them) and continue to use the $workerList array as needed.

Also, unless you need all of those $origin, etc… arrays in other passages, and not just the one that generates the co-workers, then instead of using story variables (the variables that start with $), you should be using temporary variables (the variables that start with _) for those arrays. Or, if those arrays will never change, then you could make them properties on the SugarCube setup object in either your JavaScript section or your StoryInit passage. Alternately, you could still use story variables, but <<unset>> those arrays when you’re done with them.

The reason why, is that story variables take up space in the game history, and the larger your game history is, the slower that saves, loads, and passage transitions will be. Thus, for optimal performance, it’s best to minimize the number of story variables you use, and to <<unset>> any of them when you’re done with them.

Hope that helps! :grinning:

2 Likes

Thank you for answer from master himself :grinning: I will try your suggested method.