So, I have an idea for a data structure, but I think it might be a bit flaky. Or there might be a better way to organize things. Let me show you what I had in mind:
<<set $pcPierced = {
ears: { scale: 0, desc: "" },
navel: { scale: 0, desc: "" },
tongue: { scale: 0, desc: "" },
face: { scale: 0, desc: "" } }>>
<<set $pcPiercedList = []>>
I was thinking, to save from having to iterate through the object whenever I wanted to check if something was pierced or not (checking to see if the scale key/value pair was greater than 0), I could instead just use an array to keep track of what was pierced or not. That's what the $pcPiercedList does. Whenever there's a piercing, the "ears" or "navel" string would be added to it. Then I could use an array method to quickly check if it has been, and then use dot notion on the object to access the specifics of it.
So, is that combo approach a good idea? Or should I try to just use an array in the first place, for the data storage as well? Do I need the object? Or maybe that object structure could live in the array? Anyone have any ideas for this? One way or other? Or is this combo approach pretty good (if not a bit wasteful)?
===
Hey, while I'm here... How do I get this to work?
:: Some passage
<<set $pcPierced = {
ears: { scale: 0, desc: "" },
navel: { scale: 0, desc: "" },
tongue: { scale: 0, desc: "" },
face: { scale: 0, desc: "" } }>>
<<set $pcPiercedList = []>>
<<set $pcPierced.ears.scale = 1>>
<<set $pcPierced.ears.desc = "your ears pierced, little silver sleepers">>
<<set $pcPiercedList.pushUnique("ears")>>
Blahblah.<<if $pcPiercedList.length > 0>> <<piercings>><</if>>
:: Widgets
<<widget "piercings">>
<<for _i to 0; _i lt $pcPiercedList.length; _i++>>
<<if $pcPiercedList.length == 1>>
<<print "You have ">>
<<else>>
<<print "You have a few piercings... ">>
<</if>>
<<print $pcPierced['`$pcPiercedList[_i]`'].desc>>
<</for>>
<</widget>>
This one: <<print $pcPierced['`$pcPiercedList[_i]`'].desc>> Doesn't work. I thought the `notation was meant to evaluate code fragments? Or is that not really how you use them? I I just cheat and use <<print $pcPierced['ears'].desc>> it works. As expected. But, how do I get it to work properly?
Also, if I do cheat, I see I'm getting three (3) spaced between "You have" and "your ears pierced..." So, like this: You have<space><space><space>your ears...
I can only account for one space. So, where might the other two come from? Any idea?
===
I got it. So, I'm supposed to use this, right? <<print $pcPierced[($pcPiercedList[_i])].desc>>
That works. But, I'm still getting those three spaces. So, ideas?
===
So, I eliminated the extra spaces, by changing to this: <<print "You have">>\
But, I don't get it. My widgets passage is set to [nobr]. My understanding was that I didn't need to put \ behind everything when I had that [nobr] tag. But results are results.
So, if I have <<print "hello">><<print "world">>
Woudl I expect to have "helloworld" or "hello world" as a result? Because I think that's what I'm seeing. An automatic insertion of a space that I didn't really want or desire. Or is something else happening? My code looks like this now:
<<widget "piercings">>
<<for _i = 0; _i < $pcPiercedList.length; _i++>>
<<if $pcPiercedList.length == 1>>
<<print "You have">>\
<<else>>
<<print "You have a few piercings...">>
<</if>>
<<print $pcPierced[($pcPiercedList[_i])].desc>>
<</for>>
<</widget>>
And I get "You have your ears pierced, little silver sleepers<space><space>" from it. I have no idea where those trailing spaces come from. It's weird. And I don't like it.
===
Alright, this gets rid of most of the annoying spaces:
<<widget "piercings">>
<<for _i = 0; _i < $pcPiercedList.length; _i++>>
<<if $pcPiercedList.length == 1>>
<<print "You have">>\
<<else>>
<<print "You have a few piercings...">>\
<</if>>
<<print $pcPierced[($pcPiercedList[_i])].desc>>
<<print "hello">><<print "world">>
<<print "hello">><<print "world2">>
<</for>>\
<</widget>>
But it's odd. Because right now it produces this:
You have your ears pierced, little silver sleepers in the earlobes. helloworld helloworld2 .
The way to eliminate that last odd space is it have this:
<<print "hello">><<print "world2">>\
But if I follow the same logic, and put the same behind the first helloworld, it just does this stupid thing like:
helloworld\ helloworld2.
The only way to get those helloworlds together is to format the code like so:
<<print "hello">><<print "world">><<print "hello">><<print "world2">>\
So, do I just have to be extra extra observant when I use widgets to print things out? Is it better to use macros in javascript and then assemble strings to produce the final line? Rather than doing piecemeal stuff like this? I wonder