Hi. I'm new to Twine and I've spent the last three hours trying to find something in the documentation or forum that explains my question, but I've completely failed. I'm sure this has been answered somewhere before. I'm sorry for asking again.
I want to run loops manipulate arrays in javascript using functions, and return those values for use in my normal twinecode. I really only need like three java functions for the game I'm planning on setting up, but I can't figure out how to call them from the Edit Story Javascript area. I read that for Harlowe I needed to use a global object, so I just sort of did that here for Sugarcube. IDK what I'm doing at all.
Can anyone explain to me how to make the following function run in Twine? Thank you so much for your time.
I want to run loops manipulate arrays in javascript using functions, and return those values for use in my normal twinecode. I really only need like three java functions for the game I'm planning on setting up, but I can't figure out how to call them from the Edit Story Javascript area. I read that for Harlowe I needed to use a global object, so I just sort of did that here for Sugarcube. IDK what I'm doing at all.
Can anyone explain to me how to make the following function run in Twine? Thank you so much for your time.
if (! window.rollevent) { window.rollevent = function() { var sum = 0; for ( i = 0; i < events_All.length; i++) { var sum = sum + window['event_'+events_All[i]] }; var i = 0; var total = 0; var random = Math.floor( Math.random() * sum ); while (total < random) { var total = total + window['event_'+events_All[i]]; var choice = events_All[i]; i++; }; return choice; } }