I mainly use Sugarcube. What happens is I often write <<set $var = $var + 1>>, but the $var changes very often. Rather than having to re-name both variables, is there a function like <<set $var += 1>> or something similar, where I only have to name it (thus re-name it for different instances) once, and still have the effect be the same?
Any help is appreciated.
Comments
This on Javascript sheet
And this on passage
And VariableName grows +1
I hope that helps
I would like something that increases a given variable without having to write it out twice. in <<set $var = $var + 1>>, you have to write $var twice.
I have a lot of variables with different names. So if I wanted to copy and paste the long string of code I had, I'd have to replace $var with $var2 in two positions, because I've written $var twice.
If I had something like <<set $var +=1>> then it would increase the variable and I would only have to re-write $var once, because it's only been written once.
I'm going to change the name of $var often, but I would rather not have to correct it twice for every time.
I'm not sure if this is possible with Twine's limitations but it's a java function, which Twine is based on, so I'm holding out hope.
<<set $var1 = self + 1>>
<<set $var2 = self + 1>>
<<set $var3 = self + 1>>
<<set $var4 = self + 1>>
Rather than having to write out each variable twice
Alternatively, if you simply need to increment or decrement the $variable by 1, then you could also do this:
via http://twinery.org/forum/discussion/1516/objects-are-your-friends-how-why-to-use-javascript-objects-for-total-newbies
I swear on my life I tried that in Twine 2.0.8 before asking the question and it didn't work, but copying and pasting your example does. I'm a little irked the answer was this "right in front of me" the whole time, but that doesn't matter because it works now, and my problem's been solved. Thank you.