Tutorial HTML How To Debug(Or Cheat) Twine{SugarCube} Variables

Ragnarok20

Newbie
Feb 10, 2018
47
42
Does anyone have a TwineHacker program running?
I tried, didn't succeed. Not that good a coder. I might try to do it from scratch.

Edit: This is as far as I got editing the files, in manifest version 3 you need to use 'Service_Worker' instead of 'Background', which is more secure to store your background content but it also comes with this annoying new feature where the workers goes inactive if its content isn't running and the only way to get it active again is to restart your browser (from google on "Migrating to manifest v3"). So as I understand you open a html file, service_worker sees the page doesn't need the background content (in a fraction of a second or so), goes inactive = you can't use it.
A solution I thought of was to somehow open your game (html file) through TwineHacker (with some modifications) itself meaning the custom globals would always be shown, this way 'service_worker' shouldn't go inactive. This however is not something I want to dedicate myself to doing and it would probably be more cumbersone than just doing what OP said in the 1st page.
 
Last edited:
  • Like
Reactions: Brodjaga

MLocke

Newbie
Feb 3, 2021
72
68
What problem were you guys having with the existing TwineHacker? You should be able to ignore the chrome warning about manifest v2.

I attached a version where I just converted the one file to manifest v3 format. I don't think Firefox supports v3 yet. I suppose you should use it if you think you need it.
 

Denis25

Member
Dec 4, 2017
289
190
Installed Twine as extension to chrome. However, cannot activate. Somebody wrote earlier that I need to set up keyboard shortcuts - when I go there I see only Adobe

Nvm, looks like I don't need to set up shortcut and it's working even without it.
 
Last edited:

LeakAngel

Milk junky
Donor
Jun 20, 2018
119
87
What problem were you guys having with the existing TwineHacker? You should be able to ignore the chrome warning about manifest v2.

I attached a version where I just converted the one file to manifest v3 format. I don't think Firefox supports v3 yet. I suppose you should use it if you think you need it.
Hey, I tried that but I can't seem to make it work. I tried ctrl+shift+H as it was before but nothing pops up. I tried on different games which worked before and nothing :/
 
  • Like
Reactions: Brodjaga

Ragnarok20

Newbie
Feb 10, 2018
47
42
Hey, I tried that but I can't seem to make it work. I tried ctrl+shift+H as it was before but nothing pops up. I tried on different games which worked before and nothing :/
Download the modified file (to manifest version 3) onto a folder of you choosing, unzip the file, open your browser -> extensions -> activate developer mode -> load from unpacked -> select the folder where you unziped the file. (You should see twinehacker installed and no errors showing)

After this open your game open the developer tools (depends on which browser you use but f12 or ctrl + shift + i should work, or just google how to open them for your specific browser), after this you'll see a new tab where your console, network, elements etc bar is, called twine hacker, click there modify whatever you want, freeze values if needed.
 
  • Red Heart
Reactions: LeakAngel

LeakAngel

Milk junky
Donor
Jun 20, 2018
119
87
Download the modified file (to manifest version 3) onto a folder of you choosing, unzip the file, open your browser -> extensions -> activate developer mode -> load from unpacked -> select the folder where you unziped the file. (You should see twinehacker installed and no errors showing)

After this open your game open the developer tools (depends on which browser you use but f12 or ctrl + shift + i should work, or just google how to open them for your specific browser), after this you'll see a new tab where your console, network, elements etc bar is, called twine hacker, click there modify whatever you want, freeze values if needed.
Thanks man, I didn't know we could use the console tab :)
 
  • Like
Reactions: Ragnarok20

Potatoface52

New Member
Sep 25, 2021
7
6
How to alter the variable which checks if a given scene / passage was visited?
For example when script checks for something like that: <<<if visited("intro15")>>
That would normally be achieved by modifying the SugarCube.State.passages array. Unfortunately, the passage objects in the SugarCube API are declared as immutable to avoid unexpected behavior, which means that we can't modify this array at runtime.

However, it's possible to modify it indirectly using a game disk save. You can search for an online Twine Save Editor (sorry, can't post links yet), decompress the save contents, modify the passages (this can also be used to modify literally anything that's in the game's saves), compress them, and load the modified save.

I strongly suggest that you backup your save first (basically avoid overwriting it), because it's possible to mess up during modification, and corrupt the save. Beware that modifications in save files may break a game in many unexpected ways.
 

bonzz

Newbie
Mar 17, 2018
87
42
I always get this message, could you help me out?
View attachment 1850180
It's not active variables.. it's sugarcube.state.variables

you can use code below to save the entire tree as json, that makes it a bit easier to search..

JavaScript:
data = JSON.stringify(SugarCube.State.variables, undefined, 4);
filename = "console.json";

var blob = new Blob([data], {type: 'text/json'}),

e = document.createEvent('MouseEvents'),

a = document.createElement('a')

a.download = filename

a.href = window.URL.createObjectURL(blob)

a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')

e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)

a.dispatchEvent(e)
 

greyelf

Well-Known Member
Nov 16, 2016
1,076
789
I always get this message, could you help me out?
View attachment 1850180
As previously stated, the correct syntax for accessing the Story Variables of a SugarCube 2.x based project is...
Code:
SugarCube.State.variables
...but that command won't work if the Twine project was built using a Story Format other that SugarCube 2.x so which project are you trying to use that command on?
 

Miðgarðsormr

Engaged Member
Oct 1, 2017
2,471
6,074
I am old and i am using opera gx. And i have not the slightest clue how any of this works. Could someone explain to this grandpa here how this works with my browser or should i watch some tutorials how to work on the browser first? (don't want to waste someones time if i don't understand half the stuff you guys talking about)

Thank you guys.
 

Lure of Chaos

Member
Apr 21, 2020
113
100
other news: i've submitted extension to Google and Mozilla stores, so anyone will be able to install it easily. So we are waiting to pass all checks and be published
i'll write here and on Github when it's done
 

Lure of Chaos

Member
Apr 21, 2020
113
100
hmm, some news...
Google has decided that this extension violates but don't explain anything.
i don't know how to get request - is any cheating software banned or what?

maybe any of you could help, as i have no experience in such deeds
 

sadiyaflux

Newbie
Oct 18, 2020
29
29
As previously stated, the correct syntax for accessing the Story Variables of a SugarCube 2.x based project is...
Code:
SugarCube.State.variables
...but that command won't work if the Twine project was built using a Story Format other that SugarCube 2.x so which project are you trying to use that command on?
Harlow =) And for the life of me - I can't find the correct branch with the current game state variables. It's not a big deal, but I'd like to cheat in my (ever growing) Harlow-Format section. I would be very happy if someone could provide some insight here ^^ oc, If all things fail - I need to peruse their documentation....
 

greyelf

Well-Known Member
Nov 16, 2016
1,076
789
Harlow...
I'd like to cheat...
If all things fail - I need to peruse their documentation....
While it it technically possible to gain access to the variable State of a Harlowe based project, doing so requires a lot more effort than it does with a SugarCube based project. Because Harlowe's engine:

1. has been deliberately designed to restrict an Author's ability to use JavaScript to access its internals.
2. has no documented JavaScript API, nor a "debug" object like SugarCube does.
3. uses a different type of History system than SugarCube, and if you don't know what you're doing it is easy to corrupt the historical state of "collection" based objects like Array & Data-map.

So if you're willing to edit the contents of the generated Story HTML file, or to de-compile and re-create your own HTML file. Then adding the following Scope Escalation Hack code to the Story JavaScript area of the project...
Code:
if (!window.Harlowe){
    window.Harlowe = {"State": State};
}
...will allow you to use Harlowe.State within your web-browser's Console to access the engine's State object.

What you do once you have access to the State object is not totally clear, because its structure was changed in the most recent versions of the Story Format.
 

sadiyaflux

Newbie
Oct 18, 2020
29
29
Thank you kindly, Greyelf! Worked like a charm. It's more complex to find state variables relevant to effective cheating, but this gives me enough access to bend any given scene to my headcanon. Again, thx!