Function – Talk
It should be mentioned somewhere that a "function" is the same thing as the code data type.
I'm afraid we are making things much, much more confusing by creating arbitrary distinctions like a "function" instead of "code".
Note that in OFP, there was no code data type. So "code" was just a special type of string. In that case, it made sense to call that special type of string a "function".
But in Arma, there is, in fact, a specific data type called "code". So introducing an extra term, "function", makes things more confusing.
The distinction we need to be making is the difference between running code when using 'spawn' versus running code using 'call'. In that case, it might make sense to use the term 'function' to refer to code run via call as opposed to that being run with spawn. But this article calls both 'functions'.
So my point is that this article just confuses the issue. This article could replace "function" with "code" (meaning, the data type), and it would be more helpful imo. At the moment, we are just making up new terms and confusing things quite a bit.
--General Barron 09:22, 16 January 2009 (CET)
suspense of functions
I just tested it, but it is -- even in ArmA -- not possible to use sleep or waituntil in functions, at least not if you want to use it from a SQS script. call does nothing more than "removing" the curled braces, so this example (eg in a init.sqs) brings up an error:
~2
hint "now"
call {sleep 2; hint "done"}
If you're calling a function from a SQF script it works, sure.
I'm not really sure how we can explain that in an easy-to-understand way on thís page :/
--raedor 02:34, 21 December 2006 (CET)
- Other than this issue, there seems to be no difference between inline functions vs compiled functions. Maybe this should be mentioned on the page. It'll save some trouble to load a big set of tiny functions from a single file compared to having each preprocessed and compiled from its own file. Pulverizer 13:28, 9 April 2007 (CEST)
Old discussions
How can engine know if I want to use standard or semicolon free variation? In both is first command semicoloned... --Djura 19:34, 24 July 2006 (CEST)
- There is no semicolon free in function-based syntax. Watch the examples, they all have semicolons to separate instructions. When no semicolon, it's a curled-brace, ie an "embedded" function line, or set of instruction. The semicolon free syntax exists in current OFP-style scripts, launched by exec. If I'm not mistaken, once you launch things through call, spawn or execVM, you're using function syntax that requires semicolons to separate instructions. If you still use "exec", you're using OFP-style syntax --Whisper 19:44, 24 July 2006 (CEST)
The deprecation of scripts has not been clearly explained. The proper explanation here and in Script syntax should be that SQS-script syntax has been deprecated in favour of SQF-script syntax(I am coining the term SQF-script for lack of a better alternative). The differences between an SQF-function and an SQF-script are:
- 1) SQF-scripts can not return values
- 2) SQF-scripts can pause and wait using the sleep and waitUntil commands
- 3) SQF-scripts are run in parallel via the spawn command.
The comments about script deprecation so far led me to believe that all functions would have to run in parallel. I doubt I am the only person so confused.--Mr.Peanut 21:28, 26 September 2006 (CEST)
- The content in Scripts is concise. I think it's the function page that creates the confusion, using terms like "function based script"?
- I'm not sure why the original terminology was dropped? Calling something a script function is a bit confusing. Scripts (*.sqs) Functions (*.sqf) make code that bit easier to understand. If your looking at a *.sqf file, then you know it's supposed to be executed with the call command. Vice versa for scripts, a *.sqs is supposed to be executed with the spawn and execVM commands? That fact that scripts now share the same syntax as functions, should be easy enough for most people to grasp. Without having to create a whole new lexicon. UNN 02:28, 27 September 2006 (CEST)
- I would really recommend not using sqs for the structed syntax scripts. There are even instances in the game where both new and old syntax is accepted, and old syntax is used for sqs extenstion (like init.sqs, init.sqf). --Suma 15:28, 27 September 2006 (CEST)
- I was referring to *.sqs purely as a file extension. For a new user coming to the wiki and scripting for the first time, they should just be told to use the new syntax for scripts. As you mentioned both functions, scripts, new and old syntax will be interchangeable in some cases. But that IMHO would just confuse a beginner and should probably left to advanced topics. But I may have misunderstood your reply, so sorry if I missed the point. UNN 23:49, 27 September 2006 (CEST)
- In any event, these wiki pages are sowing confusion by wantonly mixing the terms. For example, the execVM page uses both function and script interchangeably in its text. Perhaps a better lexical differentiation would be "parallel" and "serial". Users will have loads of fun trying to decipher whether a particular SQF file must be executed via spawn, execVM or call compile. I suppose the user community will sort it out by either defining a new file suffix (e.g. SQP for parallel function/structured script/whatever you want to call it) or requiring a header with the necessary information. --Mr.Peanut 16:42, 27 September 2006 (CEST)
Fresh air
Is not better to show the use of "BIS_fnc_param" function for get param, in addition to the old way?
--Floriangeyer (talk) 11:34, 17 July 2014 (CEST)
How to call a function nested in a script?
Say I have a list of functions inside a script, almost as a repository for them. How can I call them? Is there a method for that? i.e. [] call function in script