Author Topic: [Tip] Splitting scripts  (Read 2028 times)

Dav999

  • Global Moderator
  • Captain
  • *****
  • Posts: 2181
    • View Profile
    • The Open Level Project
[Tip] Splitting scripts
« on: August 11, 2012, 10:59:39 am »
A lot of people must have encountered it at least once. You make a level with a very long script, and when you press enter to test it: BOOM. The game crashes. And whether you saved it or not, one thing is clear: the script is too long, and it either needs to be made shorter or split into different scripts. And if you are going to split it, is making a screenshot of the second half and typing it all again in another script the best option? No, because there is an easy way to split a script without even having to create a new script with a terminal or script box (and this has nothing to do with opening the level in a text editor)

I'd recommend making a backup of your level first (just in case anything goes wrong, which is not likely if you do it correctly.)

So, if you want to split a script called thishastobesplit, which contains this:

Quote
say(2)
This is a very
simple script.
say(4)
This isn't too
long, but we
just want to
test splitting.

You need to type this in order to split it:

Quote
say(2)
This is a very
simple script.
iftrinkets(0,thishastobesplit2)
thishastobesplit2:

say(4)
This isn't too
long, but we
just want to
test splitting.

I used thishastobesplit2, but it can be anything except a name with capital letters in it.
After that, save your level, quit the editor, and open your level again in the editor. Now, there are two scripts instead of one!

You can also split a script in more than two pieces, by doing this at each place you want to split. You don't have to split it in two, restart the editor, and then split it in two again, this:

Quote
say(2)
This is a very
simple script.
iftrinkets(0,thishastobesplit2)
thishastobesplit2:

say(4)
This isn't too
long, but we
just want to
test splitting.
iftrinkets(0,thishastobesplit3)
thishastobesplit3:

say
This is part 3.

...will split it into three parts.

This works because all scripts are stored after each other on one line. The lines are separated by vertical bars (|, ä in-game), and each script is preceded by it's name, followed by a colon (:) (which is why you cannot use these characters in scripts). That way, you can even type ALL of your scripts in one script, as long as you quit the editor and start it again before you test the level. You have to restart the editor after you used this, because the script will not be split until you restart the editor.

FIQ

  • Captain
  • *****
  • Posts: 811
  • https://github.com/FredrIQ/
    • View Profile
    • FIQ
Re: [Tip] Splitting scripts
« Reply #1 on: August 11, 2012, 02:23:42 pm »
I didn't realize that you could do this, so I splitted the hard way when I needed it. Neat! :)

blue626

  • Captain
  • *****
  • Posts: 672
  • I changed my avatar!
    • View Profile
Re: [Tip] Splitting scripts
« Reply #2 on: August 11, 2012, 03:38:50 pm »
... That was probably not intended, am I right? So, I will not use it. Splitting scripts the "hard" way is, in my opinion, as hard as the "easy" way (because, in the easy way you have to save, quit and load) so I'll keep DTTHW :D (do you understand?) :D.

This works because all scripts are stored after each other on one line. The lines are separated by vertical bars (|, ä in-game), and each script is preceded by it's name, followed by a colon (:) (which is why you cannot use these characters in scripts).

That explains why the following glitch happens (at least in v.2.0.). That glitch can only happen if you make a mistake while writing a script.
If you write this at the end of a script:

say/reply(x)
(x-1 lines of dialog)
(empty line)


x is a number between 2 and 5, obviously.
When you test the script, the terminal (or :viridian:) will say this:

(the same x-1 lines of dialog)
(name of the last modified script besides this one):

Dav999

  • Global Moderator
  • Captain
  • *****
  • Posts: 2181
    • View Profile
    • The Open Level Project
Re: [Tip] Splitting scripts
« Reply #3 on: August 11, 2012, 04:47:03 pm »
... That was probably not intended, am I right? So, I will not use it. Splitting scripts the "hard" way is, in my opinion, as hard as the "easy" way (because, in the easy way you have to save, quit and load) so I'll keep DTTHW :D (do you understand?) :D.

This works because all scripts are stored after each other on one line. The lines are separated by vertical bars (|, ä in-game), and each script is preceded by it's name, followed by a colon (:) (which is why you cannot use these characters in scripts).

That explains why the following glitch happens (at least in v.2.0.). That glitch can only happen if you make a mistake while writing a script.
If you write this at the end of a script:

say/reply(x)
(x-1 lines of dialog)
(empty line)


x is a number between 2 and 5, obviously.
When you test the script, the terminal (or :viridian:) will say this:

(the same x-1 lines of dialog)
(name of the last modified script besides this one):


Or it will just crash the game if there is an empty line, except if you open another script after that one.


To give an example of what scripts looks like in the .vvvvvv file:

<script>script1:|say|This is a script.|script2:|say(3)|This is another script.|It is unrelated to the other ones.|I will destroy gravity lines now.|destroy(gravitylines)|sad|reply|Why did you do that?|delay(30)|happy|script3:|say(2)|This is script #3 and is not related|to the other scripts.|loop:|say(4)|This script was meant to loop|infinitively by going to this|script over and over, but sadly,|it didn&apos;t work. :-(|</script>

Note that some special characters get changed, like ' will be changed to &apos; because otherwise it may conflict with other xml things will get difficulties. So I decided it was a good idea to test what would happen if I wrote </script> in the very first script. They also thought of this and it got changed to &lt;/script&gt;.