Hi!
I am currently using twine for something rather untypical, a random map generator. Which works fine by the way. I only have the problem, that in some situations i need very long loops, which are aborted after a certain amount of iterations. I could split the loops up, but that would just bloat the code. There seems to be a way to change the number of maximum iterations in sugarcube, but is there one for vanilla twine too?
Comments
Then, for the vanilla story formats, the only solutions are likely to either split up your recursive passage display into more manageable chunks or to begin using JavaScript loop statements.
You might be able to restructure your code to get some extra mileage out of it, but that would depend on what exactly the "abort" is. I'm guessing you're probably running into the browser's built-in execution limit, but I suppose it's possible you're hitting something else. When you say your code is getting "aborted", are you talking about the "script is taking too long" popup?
While there are differences between the vanilla story formats and SugarCube, either() is not one of them.
I get the following error-message under chrome: <<if>> bad condition: $auswahl[$auswahl.length - 1] neq -1
i thought it was a twine thing, but if it is a browser related issue I guess I'll really have to resize the chunks...
Thanks for the posts so far...
The original loop <<suche>> did the following: It would search the array $map for a value ($gesucht), write the position of every find into the $auswahl array, starting at 0 and always picking up the search one position after the last find, until the indexOf method would return -1 because there are no more values like the one searched for in the array.
Could this loop be implemented as sugarcube for-loop without creating errors even at large numbers of itinerations? Unfortunately I have no clue about JS...
That's kind of an odd error, considering the expression it's complaining about. I get the feeling that something else is going on there.
Yes. For example, using code similar to what you're using now (i.e. using
indexOf()
): The backslashes are there solely to keep output from being generated (from the line-breaks).Alternatively, for something which will also work in the vanilla story formats, since you're already tapping the array
indexOf()
andpush()
methods (which are JavaScript, BTW), you could also simply do it with the arrayevery()
method. For example: Thev
andi
parameters are the current array element's value and index, respectively. The function passed toevery()
only pushes the valid indices onto$auswahl
, so that is why the second<<set>>
is there, to push a final-1
on, just like your original faux-loop does.[URL=http://imgbox.com/9OgLZOSv][IMG]http://5.t.imgbox.com/9OgLZOSv.jpg[/img][/URL]
I find the MDN JavaScript reference to be fairly friendly.
I'll also note that using
every()
as I did is a little contrived. It works perfectly well, but what you really want to use there isforEach()
, which would obviate the need for thereturn true
in the callback. I usedevery()
instead, since I don't believe the vanilla story formats polyfillforEach()
and they support older browsers where it doesn't exist.