OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Proxemo on 22 Sep 2007, 11:39:57
-
Hello. I consider myself new to scripting but here is the thing. I would like to know if it is possible to tidy things up. What I mean by this is right now I have script per trigger and I have quite a few triggers. Is there a way where instead of having a script per trigger, I am able to merge some scripts together and refer them to triggers on the map?
In other words, can I have trigger (A) point to a specific portion on alpha.sqs and trigger (B) point to a different portion on alpha.sqs? These triggers are activated by blufor presence.
-
Alright, so your idea is to make a huge script of which different portions are activated depending on which triggers activates the script?
To do this:
split your alpha.sqs into several portions by using:
; start of script
goto (_this select 0);
#portion1
blablabla.. code code
#portion2
blabla.. code code
And in each trigger:
["portion2"] exec "alpha.sqs";
This will send an array to the script (with parameters), here the array (1st element) contains a string "portion2".
At the start of the script, I extract this string out of the array passed to the script and use it to go to the correct portion. Should work.
-
That is exactly what I want but a quick question.
Do I have to put "end" at the end of every portion or will "portion" end the previous command for me?
-
u shud use da exit (http://ofpec.com/COMREF/index.php?action=details&id=126) command after each part...
if u use functions on the other hand (highly recomended... they work beter :D)
u wud have it look dis way
if ("portion1" in _this) then
{
code
};
if ("portion2 in _this) then
{
code
};
and then u wont need any exit command :D
LCD OUT
[edit] oops... some strange bug in my msg... fixed :D
-
Another way of doing it with sqf is using the switch command.
_event = _this select 0;
switch (_event) do
{
case "SomeEvent":
{
some commands here
};
case "AnotherEven":
{
some different commands here
};
case "YetAnotherEvent":
{
Evenmore here.
};
};
I used this structure for a cam script recently, where i could include the intro, outro cam, and some middle cutscene all in the same script.
-
Appreciate your help fellas but when I try to use an sqf file, I receive the error:
'|#|;}'
Error Missing {
Like I said earlier, I am new and have only used sqs files. Since you guys introduced me to sqf, I have no clue on how to fix it. I don't know the syntax so whether it is a missing { or something I have done, I have no clue.
-
it may b cuz of how u called da function (bla = [parameters] execVM "functionname.sqf" is wat u need... dont use exec)
if its not dat... its probably cuz u have a missing { :P
go check dat } in ur function has a matching { somewere :P :D
LCD OUT
-
Also remember that .sqf scripts are generally nearly identical in use to .sqs (don't try to say different here, OFPECers, you can use all the same for...do, while...do, if...then...else forms in .sqs as you can in .sqf ;) ), except that .sqfs need a ; after every finished command, and uses sleep instead of ~ for waiting. Oh, and you can't use goto, of course. ;)
(I think of .sqf as glorified trigger-line mini-scripts, really).
Wolfrug out.
-
Here (http://www.ofpec.com/ed_depot/index.php?action=details&id=390&page=0&game=ArmA&type=tu&cat=xyz) is a tutorial about SQF scripting.
-
I advice against putting everything to a single file.
That's for sure not a programming practice you will thank yourself later.
The problem with putting too much into one file becomes clear when your script gets big. You will have trouble managing it, and keeping it error-free. The goto style programming is a sure way to confuse yourself, I suggest to avoid that. It's just too easy to make an error when building big scripts which use goto, so it's best to avoid it if you can, and yes you can avoid it.
Write small functions to accomplish clearly defined tasks. Some good examples can be found from the Editors Depot. Then use those functions together to accomplish the tasks your code needs to do in your mission. You will need to carefully determine which parts of your scripts can be separated into functions. Think about things which can be done so that the function does not need to know anything specific to the mission you are creating, or anything specific to other functions (try to keep dependencies to minimum and you will have re-usable code). For example one clear rule I can give to you that your functions should not have to rely on any global variables.
This is definitely the way to go instead of writing one big script which tries to handle the whole mission.
You should try to separate:
- Utility functions/scripts which do small tasks, and need not to know anything specific to your mission in order to work. An example of what one such file could do: eject a group out of a flying helicopter.
- Mission logic functions/scripts, these are the ones which use the utility functions/scripts to accomplish some small sub-tasks in a certain order and timing. An example: a script which makes the helicopter fly into a drop zone, and then calls the utility function to eject the group.
-
Thnx for the reply fellas. I haven't tested it out yet but I just wanted to say thanks again. I'm not putting the entire mission into one sqf. It is mainly for text (hint/hintc) commands. I'm making a tutorial and I have a lot of these running around. I thought that the more sqs files you have the slower/longer you it will take to load. Not sure if there is any validity to this.
As far as sqs/sqf, I have to do more reading on the subject. Right now they are the same to me but Baddo cleared things up a little bit. I appreciate it.
-
I thought that the more sqs files you have the slower/longer you it will take to load. Not sure if there is any validity to this.
Hmm, they aren't all active at the same time, thus if you have five of 1kb each and only one is active you have 1kb in the cache. While this is 5kb if they are all in the same file. Notice that it isn't as simple as this ;)
-
I would do something like this. I've become a big fan of the switch command. :good:
init.sqf or init.sqs
Chatter = compile (preprocessFileLineNumbers "chatter.sqf");
To call the particular event
["SomeEvent"] call Chatter
chatter.sqf
_event = _this select 0;
switch (_event) do
{
case "SomeEvent":
{
Hint "some commands here";
};
case "AnotherEven":
{
HintC "some different commands here";
};
case "SideChatEvent":
{
player sidechat "A sidechat even";
};
};
This loads the chatter.sqf when the mission loads, and then when you use call it pulls the text from memory.
-
Thnx for the info. Again forgive the noob questions but to what hoz wrote:
What advantage does switch commands have over sqf?
I came in thinking sqs was the way to go and I learn 3 different ways of writing it :P
My head hurts >:(
Thanks again fellas.