Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Pulling the 'name' from a name/value pair

Hi All,

First time poster so hopefully I do this right.

Twine 2.0.11, Sugarcube 2.8.0

I've created an array and successfully sorted it like so:
<<set _statroll = [["will",random(1,20) +$player.will],
["str", random(1,20) +$player.str],
["dex", random(1,20) +$player.dex],
["con",random(1,20) +$player.con],
["wis",random(1,20) +$player.wis],
["int",random(1,20) +$],
["chr",random(1,20) +$player.chr]

before:<<print _statroll >>

<<print _statroll.sort(function(a,b){return a[1] - b[1];})>>
<<print _statroll [6]>>

My goal is to determine the maximum roll each time this passage is visited and provide different options based on what that maximum was.

My issue is that when I print the _statroll[6] I'll get something like "will, 13" when all I really want to see is "will".

Is there a way to do that?

Any help is appreciated.



  • You're dealing with nested arrays. To yield a member of one of the nested arrays, simply index it.

    For example:
    <<print _statroll[6][0]>>
  • Thanks TME, that worked perfectly. I figured it was something simple but for some reason didn't think that would work.
Sign In or Register to comment.