Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

How to work with large numbers of randomly generated NPCs

$
0
0
Hi guys, apologies if anything I ask below seems obtuse. I've tried searching various forums without any real success, but I'm not a coder so I'm struggling either way.

I'm using Twine 2.x and SugarCube 2.x (latest versions as of a few days ago)

I want to create a game that will handle lots of NPCs (10+) and track their stats independently. Specifically, I'm generating named, but expendable mercenary NPCs who I'd like to be able to create, equip, upgrade (in a limited fashion) and then send off to fight and/or die.

At present I have a test passage generating these NPCs (eventually this will have to be done more organically, obviously). I'm generating each individual NPC as an object:
<<set $currentmerc to {"mercID": 1, "mercName": "Waaaagh", "mercCP": 100}>>

Then once generated, the NPC is slotted into an array with all his/her little NPC buddies:
<<set $mercs.push($activemerc)>>

At the moment, if I want to inspect, equip or otherwise modify my NPC then I'm copying the data from $mercs to $currentmerc and then manipulating it there (since this can be done in a dedicated passage)
<<set $currentmerc to $mercs[_whichevermerc]>>

The things I would appreciate some help with:
  • Any suggestions for how to build a screen which lists all of the (currently living) mercs and creates a clickable link over their name to take me to a customisation screen? At present I'm using a for loop to pull from the $mercs array, but it breaks whenever I use $mercs.length (see appendix 1 below)
  • Any general suggestions about how to better manage this data?
  • Lots of mercs are going to be dying, or get fired. How do I go about removing them cleanly from the array? Do I figure out what their array index is and then delete it?
  • Finally, somewhere down the track I'd like to implement the ability for the mercs to spar each other for EXP, any pointers on how I can implement this?

As always, any help is much appreciated.

Appendix 1:
<<for _i to 0; _i lt $mercs.length; _i++>>
     [[$merc[_i].mercName|InspectMerc][$currentmerc to $merc[_i]] is standing at attention.
<</for>>

Viewing all articles
Browse latest Browse all 1844

Trending Articles