Skip to content

Scripts for beginners.

User Avatar
#101
Auto-translated
Could you please elaborate a bit more? Break it down into smaller parts, if possible.
This is a common approach for any programming language: if you use a complex construct multiple times (and MessageBox will definitely appear more than once on the map), you can move all the repetitive routines into a separate function and only write what changes from time to time. For example, in your case:
MessageBox("/Maps/SingleMission/Scenario 1/quest1.txt");
Each time, you will repeat:
MessageBox - a relatively short function name, but you can come up with an even shorter one.
"/Maps/SingleMission/Scenario 1/" - the path will probably be the same for all text files.
".txt" - the file extension also does not change.
As a result, everything that will be repeated is described once in a new function, with a convenient and preferably short name. Only the changing part - the file name - is passed to the function. The ".." operator concatenates the lines into one. The second parameter of the function, cb, is similar to the second parameter of the original MessageBox (I won't explain its meaning, there is documentation for that). The second parameter is optional and can be omitted.
-- a wrapper function around MessageBox. Place it somewhere at the beginning of the file:
function MsgBox(text, cb)
MessageBox(GetMapDataPath()..text..'.txt', cb);
end

-- an example of calling the message, instead of MessageBox("/Maps/SingleMission/Scenario 1/quest1.txt"); you can simply write:
MsgBox('quest1');
If you carefully examine your code, I'm sure you will find many similar places where you can optimize cumbersome constructs.

P.S. Of course, if you are planning to write 100 lines of code for the map and that's it, then you can ignore these tips.