0 votes
by (160 points)
edited by

I'm using Tweego w/ sugarcube v2.25.0. I have a widget that handles the function of handling items, for simplicity's sake I'm stripping it down. As even then it doesn't function correctly, I'll also add that running the exact same line of codes in Twine 2(the software) w/ sugarcube 2.21.0 has it working flawlessly.

Here's the code that sets variables and calls on the widgets in question <<buy>> & <<Sell>>,  The div classes are because I'm using CSS to sort the text into grids

<div class="items"> 
<<ItemSnacks>> /* widget */
<<print _retailValueCS.Snacks>>$

</div>

<div class="items"> 
<<button "Buy">> 
<<set _selectedItem to "Snacks">> 
<<Buy>>  /* widget */
<</button>> 

</div>

<div class="items"> 
<<button "Sell">>  /* widget */
<<set _selectedItem to "Snacks">> 
<<Sell>>
<</button>> 

</div>

Clicking either button calls on the widget <<Buy>> or <<Sell>>. Here are the widgets

<<widget "Buy">>
	<<set $pc.inventory.pushUnique(_selectedItem)>>
<</widget>>

<<widget "Sell">>
	<<set $pc.inventory.delete(_selectedItem)>>
<</widget>>

Their actually supposed to handle more code, but i've stripped it to simplify the issue. The problem here is that .pushUnique() doesn't work properly in Tweego. In Twine 2(software) it's works fine.

After "Snacks" has been pushed into $pc.inventory. It's strings are pushed out like this; 

<<print $pc.inventory>> becomes: Wallet, Knife, Snacks, Snacks, Snacks.
Which is not correct, in Twine 2 the same command pushes "Snacks" only once and multiple click doesn't add more.

Funnily enough, the <<Sell>> Widget functions correctly, it's .delete() delete any strings matching it's definition. But .pushUnique doesn't work. It's not unique, I can do .push() and it works fine but add unique and it still works but not with it's intended purpose.

Any help I can get here as to understanding why this happens?
 

Edited to make it slightly less horrifying to read the code snippets

1 Answer

+2 votes
by (68.4k points)
selected by
 
Best answer

Can you provide a working example showing the issue?  I ask because what you're reporting should be impossible.  The code for the <Array>.pushUnique() method has not changed since it was added.  Furthermore, I just ran a test with SugarCube v2.25.0 and it performed exactly as intended.

by (160 points)

I ask because what you're reporting should be impossible. 

Phew, It's stupid how reading that simple line made me realize where the issue was.
You were right, nothing wrong with the <Array>.pushUnique(). Turned out to be the compiler I used that had an error resulting in it not compiling the game after I used the function. So the version I thought I was compiling turned out to be an older version which had the <Array>.push() set to it.

I've been using a pre-setup version of Tweego from GitHub-Boilerplate, the batch file used to compile didn't show error so I never noticed the compiler failed. So user error I guess. Thanks though, would have take me longer to figure out without that short but helpful reply.

 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...