Reoccuring sequence?

Mr Flart
11 Apr 2020, 14:46

Is there a way to set save a prewritten line of code that can be reused when needed instead of writing after each event? The example, to better explain, goes like this: several times the playable character will fly on a space ship from place to place. Instead of writing out the launch text, can you just type something like "run 'whatever' string/event" (I know that isn't how it would actually be written, it's just an example)?


Deckrect
11 Apr 2020, 18:22

Hello.
I am no an expert, but you are describing is a function.
A function is a script or a grou for cripts you call back with a single instruction.


mrangel
11 Apr 2020, 18:54

If it's just printing a string, you could do that with a template.

In code view (not sure if templates can be edited in the GUI; don't think so), you could add a line something like:

<template name="LaunchMessage">Here is some long piece of text that I want to print out every time my ship launches.</template>

If I remember correctly, the best place to put it would be after all the <include lines at the beginning.

And then in your code, you can just do:

msg ("[LaunchMessage]")

If you want to save more than just a message, then functions are what you need. A function can have any amount of script inside it, and you can run it whenever you need it just by entering its name in code view. You can create them in the GUI, add code to them, and