f
s
o

s
c
r
i
p
t
i
n
g

index tutorials scripts links closetpacifist

The Topic

Say you want to create your own functions, and put them in a file separate from other scripts, so that you could easily access them from elsewhere, or carry them around? Well, that's what we'll be doing here.




The Explanation

Well, first off, we need our file, right? Well, all of the scripts end with .ls, so ours should to. Create a file with a name of something like OurFile.ls. Let's put a short function in there. Say, one which takes the name of a player, a map and coords and then warps the player there.

on WarpPlayerToMap(ThePlayer,TheMap,movie)
  movie.sendMessage(ThePlayer, "Warp", "!!! !!! " & TheMap)
  put "Warped "&ThePlayer&" to "&TheMap&"."
end

So, what's that all do? Well, it defines the function WarpPlayerToMap, which takes a player's name, a map with a set of coords after it in the same format as the /warp command, and a movie.

Movie? What's that have to do with FSO? It's an object which represents the FSO environment, more or less, and which we can interact with to do things to it. In this case, we're telling it to send the message "Warp" to the player, with the data of two nonsense words, which are required to warp someone somewhere, and the map and coords.

After that, we assemble a string which contains the player's name and the map they were warped to, and put it. Put, in this case, takes the string that you give it, and writes it to the server's log, which you can see in the window which it displays.

Alrighty, so we now have our file, containing a function. The next step is to get the server to recognize it. Searching for the names of the other scripts, which the server already recognizes, we find that Scriptmap.ls contains a list of the other scripts. So, we need to make a copy of the line which the other scripts use for our own script file, which we'll put alongside the other ones.

theMap.append( [ #movieID: "Faria", #scriptFileName: "OurFile.ls" ] )

If you scroll down a bit from that list, you'll note that there's another list of the script files, and we'll need to add ours somewhere in that list as well- add something like this to the beginning of the list.

"OurFile.ls",

Why to the beginning? Well, if we load our script first, then we should be able to access it's functions from any of the other files. If not, we can't be sure we will be able to do this- I have no idea of the rules governing this, but common sense says that this might be the best configuration.

That's it! Now we'll be able to call the WarpPlayerToMap function which we wrote from any of the other scripts.