It looks like you're new here. If you want to get involved, click one of these buttons!
<<set $planets.push([$planet = {size:"giant"}])>>
And this does appear to be working. However, I now want to loop though the array showing a list of planets, and I'm hitting a snag. I tried using code like this:
<<print $planets[1].$planet.size>>
... with the assumption I could change [1] to a loop-iteration number. But it's throwing errors. I clearly have something wrong in my syntax or my assumption of how objects and arrays interact, and I'm not sure where.
Comments
I tried: And got:
[quote]Error: <<set>>: bad expression: Invalid left-hand side in assignment
Various iterations moving quotes about threw nothing but more errors. Then I thought maybe I'd got hold of the fix from the wrong end, so I changed the push statement back and tried: And got:
[quote]Error: <<print>>: bad expression: Cannot read property 'size' of undefined
I'm sure I'm doing something dumb or flat-out misunderstanding you. Little more help? ::)
NOTE: I am assuming you have pre defined $planets as an array somewhere earlier in your code using: To add a complex object to the $planets array you would do the following: NOTE: I removed the double quotes around planet, replaced the equals sign with a colon and the square brackets with curly braces.
To display the planet.size of the first item stored within the $planets array do the following: NOTE: Because java-script arrays are zero based, you access the first element using Zero, not One.
I hope this helps
Now to add complexity and shoot myself in the foot again.
Many thanks to both of you for the hand-holding. Someday I will be able to approach a new programming language without instantly tripping over its anal grammar requirements. Someday....
You can create a display macro and use the parameter function to get the planet index: --then--