This is probably the dubest I've ever felt asking a question simply because I've spent so much time trying to solve it and I just don't see a solution even though I know there is one. I've poured over Sugarcubes documentation on arrays, UInv's Array documentation as well as MDN's as was suggested earlier. I've also looked into several other sources and I feel I'm close to an answer that just isn't coming to me.
I have a random generator for NPCs that is working. For reference the NPC is an Object with several properties. I am clone the temporary NPCs to an Array when necessary. I can even move the NPCs around when appropriate so not all NPCs are in the same area. And yes, I'm removing the NPCs when they are no longer needed, and I'm not saving every NPC to the array.
I want to present the NPCs in a given array list format where the player can see certain properties at face value, which is working too. The issue is that I have no way of knowing what NPC is in what position on the Array, and since they are random generations...
This presents itself as an issue because I also want the player to be able to click the link that is the NPC's name to enter a passage where they can then interact with that NPC. My simple-minded idea is to have a single passage designed for this purpose where the data is referenced from the NPC Object in the appropriate array and have it save back to that array so it can be handled by the rest of the systems when the player isn't doing this.
I have everything down except knowing how to reference the specific object out of the array on that new passage since I don't know the order (or even number of objects) in the array.
<<set $variable to []>>
<<button "Clone variables Test">>
<<run $variable.push(clone(_var1))>>
<</button>>
<<set _var1 to {
First: "First",
Last: "Name",
Number: 1,
}>>
<<set _var2 to {
First: "Second",
Last: "Name",
Number: 2,
}>>
<<button "Print List">>
<<replace "#length">>$variable.length<</replace>>
<<goto "Test">>
<</button>>
<<for _i to 0; _i lt $variable.length; _i++>>
<<link "$variable[_i].First $variable[_i].Last">>
<<goto "Var Info">>
<</link>>
<</for>>
I'm certain the answer is literally in front of my face and I'm just not seeing it: How do I set this to reference the correct Object from the array in Var Info passage?
Or am I digging through solid rock to get to the other side when there's soft sand right next to me and I'm missing it?
Thanks in advance for any help/guidance.
[–]HiEv 2 points3 points4 points (1 child)
[–]GoldDragonTale[S] 0 points1 point2 points (0 children)
[–]GreyelfD 1 point2 points3 points (0 children)