Howdy, Stranger!

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

[sugarcube 2] How to evaluate variable?

Hey, I know I've seen this kind of thing done before, but I'm not sure how to find the examples again.

What I'd like do do is something like this:

<<widget "setStats">><<set $player.str to $startingStats.$args[0]+$args[1][0]>><</widget>>

Given that $args[0]+$args[1] = "humanmale", and that $startingStats.humanmale holds an array of numbers, the first of which is 17. I'm thinking I should be able to get to those numbers like this somehow, but, I can't remember what syntax I need for this. I know this is possible, just... can't figure out how to do this.

So, we've got :
$args[0] = "human"
$args[1] = "male"
$startingStats.humanmale[0] = 17

How do I properly join and then evaluate the property in order to access it?


  • Ah, I worked it out. For those that look this up in the future, the formatting is this:

    <<widget "setStats">><<set $player.str to $startingStats[$args[0]+$args[1]][0]>><</widget>>

    (ie, without the dot notation.)
  • That's called the square bracket notation, for obvious reasons, and yes, that is how you should do it.
Sign In or Register to comment.