Twine 2.3.16 Sugarcube 2.5 array methods?

Hi,

Looking at the Sugarcube documentation, there are some new methods which seem to make array handling a bit easier. They are listed at [SugarCube v2 Documentation]. These new methods (including $arrayname.delete) and are listed as being introduced for Sugarcube v.2.5.0. But I can’t find any way to incorporate them. Going to download Sugarcube separately seems to take me to the 2.3.16 version included with Twine at the moment. Are these new methods not currently available or am I missing something?

Thanks,

Ian

Currently the latest released version of the 2.x series of SugarCube is v2.36.1, which is available for download in the Downloads section of that site’s main page.

You didn’t state where you tried to download SugarCube 2.x from so I can’t explain why you’re ending up with a copy of v2.3.16 instead of v2.36.1

SugarCube v2.5.x is old—released in 2016. The version that comes bundled with Twine v2.3.16 is far more recent.

Hi,
The current version of Twine appears to be 2.3.16 on the Twine website, and is listed as that in my version as well.

Hi. Thanks for this. So 2.5 is earlier than 2.3.16? That seems odd! The current version of Twine and Sugarcube I’m using (2.3.16) doesn’t seem to have $array.delete which is listed as 2.5 so I thought (I hope not unreasonably) that 2.5 might be a later version especially as 2.5 > 2.3.16!

Ian

You’re conflating the Twine version with that of SugarCube’s. They are not the same thing.

Check the formats menu to see the versions of all bundled story formats.

As far as SugarCube goes, specifically, if you’re using Twine v2.3.16, then it should come bundled with SugarCube versions v2.36.1 and v1.0.35. Make sure you’re attempting to use the correct version.

SugarCube release notes, by version, for reference.

Thanks, and my apologies, you are correct. I am using 2.36.1 of Sugarcube.

The issue remains though - the $array.delete method doesn’t work unless it is preceded by ‘run’. So:

<<$inventory.delete(“a small rusty key”)>> produces ‘<<[function](“a small rusty key”)>>’ on the screen (even though .delete is included as a method in the documentation, and functions like .push which are listed in the same way work with this syntax), whereas:

<<run $inventory.delete(“a small rusty key”>> does work. Now that’s a small thing, but it seems odd that I have to put ‘run’ in front of some of the methods, but not others.

Thanks,

Ian

Thanks to @TheMadExile I realise my error here now - apologies.

Best wishes,

Ian

What object methods do you think you can execute without running them within a scripting instance? For example, within Story JavaScript, as argument to expression type macros (e.g., <<if>>, <<run>>, <<set>>, among others), and as content to the <<script>> macro.

I’m unsure if you’re confusing object methods and/or functions with macros, but they’re different beasts.

Thanks for replying.

Here’s what I think is going on. I’m including code in links so:

<<if $ub40 == null>>
There is a UB40 here. [[Take UB40|Lounge][$inventory.push(“a UB40”); $ub40=true]]

Works - and doesn’t need ‘run’ (or <<…>>) to be included. However, I’ve now realised that this works for $inventory.delete as well, so long as it is inside a link too. Outside of links I need to use <<run…>> but inside of links I don’t. That seems to be how things work…?

Thanks again,

Ian

The part of the link markup you’re referring to is the setter component, which is the equivalent of using <<set>>.

Thanks. I think I get that now. I am still getting my head into Sugarcube. I think the problem is that I am still translating from other programming languages rather than thinking natively - I know the logic I want, but don’t have the equivalent in Sugarcube to be able to express myself yet. But I will keep trying!

Thank you again,

Ian