Twine Version: 2.3.9
Story Format: SugarCube 2.33.2
I have a passage that is called from multiple places (cell, laptop, desktop, etc.) where the player can buy and read ebooks to increase their stats. I have everything working except for one thing. I have a passage set up for the text of each ebook, and I’m trying to open it in a pop-up window, so it can be read and closed without changing the underlying passage. For example, I have an array of ebooks that looks like:
<<set $ebooks to {
basiclockpick: {
name: 'Lockpicking for Dummies',
description: 'Basic introduction to lockpicking',
intellect: 10,
reflexes: 10,
owned: false,
price: 20,
},
advancedlockpick: {
name: 'Advanced lockpicking',
description: 'Opening almost any lock',
intellect: 70,
reflexes: 70,
owned: false,
price: 100,
}
And here is how I iterate the loop. Everything works nicely so far, including buying and proper IF statements for buying/owned/not enough money, except for when trying to read and it opens a new pop-up dialog. In this sample, I have two passages called “basiclockpick” and “advancedlockpick” which match the name of the _name variable.
I’m guessing it’s due to the use of the ‘_’ variable as, as I use other pop-ups like this with static passage names and they all work properly. I don’t think the JS can access the temporary variables? If so, is there a way to do this without creating more global variables?
<<for _i, _name range $ebooks>>\
<<hovertip 'Description: _name.description<br/>Intellect: + _name.intellect<br/>Reflexes: + _name.reflexes'>><<print _name.name.toProperCase()>><</hovertip>>
Price: $$_name.price
<<if _name.owned>>\
<<link "Read">>
<<script>>
Dialog.setup(State.getVar("_name.name")); /* Get pop-up book title name for pop-up title */
Dialog.wiki(Story.get(State.getVar("_name")).processText()); /* open the _name passage */
Dialog.open();
<</script>>
<</link>>
<<elseif not _name.owned and $mc.money >= _name.price>>\ /* if not owned and have enough money */
<<capture _name>>\
<<link Buy>>\
<<set _name.owned to true>>\
<<set $mc.money -= _name.price>>\
<<goto `passage()`>>\ /* reload passage */
<</link>>\
<</capture>>
<<elseif not _name.owned and $mc.money < _name.price>>\ /* if not owned and not enough money */
Not enough money!
<</if>>
<<set _count + 1>>
<</for>>
I’ve tried it like above, as well as:
<<script>>
Dialog.setup(State.getVar('_name.name'));
Dialog.wiki(Story.get(State.getVar('_name')).processText());
Dialog.open();
<</script>>
<<script>>
Dialog.setup(State.getVar(_name.name));
Dialog.wiki(Story.get(State.getVar(_name)).processText());
Dialog.open();
<</script>>
<<script>>
Dialog.setup(State.getVar(_name.name));
Dialog.wiki(Story.get("State.getVar('_name')").processText());
Dialog.open();
<</script>>
<<script>>
Dialog.setup(State.getVar(_name.name));
Dialog.wiki(Story.get('State.getVar("_name")').processText());
Dialog.open();
<</script>>