Home   Help Search Login Register  

Author Topic: OFPEC Function Library Launched!  (Read 14338 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #15 on: 08 Jan 2003, 01:23:22 »
dey r like scripts  ;D

nd yes just save da file as sqf nd it wil b function (if u write it right ;))

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #16 on: 08 Jan 2003, 01:31:50 »
I'd say that you allow .zips, because that would be dandy ;D

Maybe force people to make short example missions on "desert island", and have them submit that?

Especially when you're using several .sqfs.

I want the function reference to be distinctly different from script snippets - it is a reference for custom commands. I will put in a place to upload zips containing example missions in addition to the single .sqf file.

Quote
_bodyang = [_guard,_deadguard] call loadfile "getang.sqf"

This defeats the purpose of having custom commands (functions) doesn't it? This is the same as:

Code: [Select]
GetAng = preprocessFile  "getang.sqf"
_bodyang = [_guard,_deadguard] call GetAng

Except you could use the GetAng function multiple times. I think that all functions loaded to the function reference should have a name, and people should be encouraged to instantiate them via the preprocessFile command, rather than loadFile.

Quote
i want it automatic - i have som math functions dat i use function in function (based on each other  )  so if i cantel dat it requires other 1s it wil b totaly kool

I will add it.

Quote
Just wanted to clear up that first thing. I know it is like a mini-script and loads faster. Just what exactly makes a funciton more usefull? Can you perform some script-controlled action quicker with a function?

OFP will work with functions (custom commands) much, much faster than it works with scripts.

When you execute a script, it must be read from the hard disk (maybe), loaded into memory and interpreted by the OFP engine every time it is called.

When you preprocessFile a function (which is essentially a script written in a slightly different syntax) it will always be in memory, so the function acts as quicly as any other command.

So, if I made a function called GetPos2, that was similar to the command GetPos, my GetPos2 function would run at a speed similar to normal GetPos function.

If I made a script called GetPos2, when executed it would run much slower than the normal GetPos function.

When you are running a loop that executes a script on every unit in the game, for example, you are looking at a HUGE processor load. If you used preprocessed function (.sqf) files, the processor load is much, much smaller.

So, to summarise ->

  • Use scripts (.sqs files) when you are doing something that only has to be done very few times in the mission (maybe monitoring and setting objectives for example).
  • Use functions (preprocessed .sqf files) when you need to repeat a script more than once, the script is not as complicated (but note that a function can be as complicated as you like, and call other functions). An eject script, for example.


Scripts and functions are very similar - but they differ in terms of:

  • Syntax (the scripting language used with functions is slightly different to normal scripts)
  • Usage procedure (functions are preprocessed and then 'called' where as scripts are executed)
  • Functions can return values


Many of the existing commands could be done better as functions - for example if you want a dude to get out of a jeep you'd have to use:

Code: [Select]
dude action["GETOUT",jeep]
unassignvehicle dude

you could make a function called 'GetDudeOut' by putting the following into a .sqf file:

Code: [Select]
(_this select 0) action["GETOUT",jeep];
unassignvehicle (_this select 0);

(_this select 0);

preprocess the file in init.sqs with:

Code: [Select]
GetDudeOut = preprocessfile "GetDudeOut.sqf"
then call the function wherever you want with:

Code: [Select]
[dude] call GetDudeOut
THE BEST THING ABOUT FUNCTIONS, THAT MAKE THEM TOTALLY DIFFERENT FROM SCRIPTS!

Functions can return values.

In a script, the only way you could return something is by using global variables.

However, using functions you can do this:

dudewhojustgotout = [dude] call GetDudeOut

 ::)

[url removed]func_test.zip]EXAMPLE MISSION[/url]
« Last Edit: 08 Jan 2003, 03:29:29 by snYpir »
Bohemia Interactive Simulations

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #17 on: 08 Jan 2003, 01:36:30 »
its kinda clearer - but one questionok, ummm, so these commands - do they like come up in the action menu for the player to use? or do they execute exactly like .sqs? - just makes things more simple.

so, umm, how do u make a sqf file? just save from notepad as an sqf?

They don't come up in the action menu - but they could, if you wanted them to (just like you make an action menu item to launch a script)

To make them - yeah, write them and save in notepad. But remember the syntax is slightly different (see the command reference: scripting topics: functions - SQF).

I think i answered your question about how they execute in my previous post.

They are very similar, yeah.

Gotto go back to work, i will return...
Bohemia Interactive Simulations

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:BETA: OPFEC Function Reference
« Reply #18 on: 08 Jan 2003, 01:37:08 »
so - i have a shouting script which makes west units call for a medic when they are injured (just voice calling, doesnt actually make a medic come to them)

now this is used lots of times since it can be called whenever... so i could make this into a function which would make it quicker? so no lag etc?
Proud Member of the Volunteer Commando Battalion

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #19 on: 08 Jan 2003, 01:46:08 »
Quote
Except you could use the GetAng function multiple times. I think that all functions loaded to the function reference should have a name, and people should be encouraged to instantiate them via the preprocessFile command, rather than loadFile.

u wil have 2 explain lil more watu meen by dis ;) - i can use da getang function as much as i want in da way i do it now - just write loadfile "functionname"

as i c it da only difrence is dat da procces file is C-Like language while da loadfile is 4 calling files generaly  ;D

from da command referance

Quote
loadFile filename

Operand types:
filename: String
Type of returned value:
String
Description:
Return content of given file.

Example:
loadFile "myFunction.sqf"

Quote
preprocessFile filename

Operand types:
filename: String
Type of returned value:
String
Description:
Return preprocessed content of given file. Preprocessor is C-like, supports comments using // or /* and */ and macros defined with #define

Example:
preprocessFile "myFunction.sqf"

and i think u can define somthin like

Code: [Select]
GetAng = loadfile "getang.sqf"
_bodyang = [_guard,_deadguard] call GetAng

i didnt try but im prety sure ;)

so can  i keep ny things @ loadfile ? ;)

btw snYpir did u write any function?

LCD OUT

 

"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Arctic

  • Members
  • *
  • In Utero
Re:BETA: OPFEC Function Reference
« Reply #20 on: 08 Jan 2003, 02:21:59 »
I think I understand it a bit better. Thanks.
I need to try this out now...

Liquid_Silence

  • Guest
Re:BETA: OPFEC Function Reference
« Reply #21 on: 08 Jan 2003, 02:41:52 »
Quote
u wil have 2 explain lil more watu meen by dis  - i can use da getang function as much as i want in da way i do it now - just write loadfile "functionname"

as i c it da only difrence is dat da procces file is C-Like language while da loadfile is 4 calling files generaly

Um, basically, the way you are doing it doesn't take advantage of the fact that functions can be run faster, as you run it like a script...

by loading the function into a string with loadFile (which is inefficient as it reads from the HD) you load it into memory, which is then called faster with the call command...

it really doesn't matter if you are only using it once, but any more than once, and you speed up your script by loading it up first (it may not be noticable in some cases, but it's good programming to be as efficient as possible...)

so you are converting the file every single time, whereas with loadfile you convert once...

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #22 on: 08 Jan 2003, 02:53:10 »
@ liquid silence : - arghhh  ::)

*feels st00pid  ;)

dat meens dat -

if i use

Code: [Select]
GetAng = preprocessFile  "getang.sqf"

or use

Code: [Select]
GetAng = loadfile  "getang.sqf"
in da init.sqs

nd den use it in ny scripts like

Code: [Select]
_bodyang = [_guard,_deadguard] call GetAng
it wil b runing faster right ?

but it didnt exlplain da difrence between

loadfile and preprocessFile right ?

or im just totaly misiong da point ?

 ::)

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #23 on: 08 Jan 2003, 03:27:19 »
Quote
but it didnt exlplain da difrence between

loadfile and preprocessFile right ?

or im just totaly misiong da point ?

You are right :o

LoadFile appears to do the same thing as preprocessFile.

but they both use the C-like syntax, when used to load a function.

This means that you need semicolons at the end of each line etc...

I proved this by trying normal syntax and C-like syntax in the DudeGetOut.sqf file (in the attached zip)

Quote
btw snYpir did u write any function?

yes :P

the example for my little mini-tutorial up above is attached.

Quote
so can  i keep ny things @ loadfile ?

um, yeah, guess so. but your functions need to use the C like syntax please
Bohemia Interactive Simulations

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #24 on: 08 Jan 2003, 03:32:43 »
chek ur IM snYpir  ;) ;D

nd i write all my functions using C like syntax :P - and u can ask messiah how meny functions i have in my script ;)  :P

i just feel beter using loadfile (cuz i know exactly how 2 write it unlike preprocessFile (i copy it from ur posts ;) ;D)

so if u reply 2 my IM it wil b kool  ;D

nd i have som functions 4 u - once u reply 2 it ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #25 on: 08 Jan 2003, 04:55:21 »
After a little more testing, I think that preprocessFile is the way to go.

preprocessFile -> Compiles the file (most probaly into machine code in memory)

loadFile -> copies the content of the file line-by-line into memory

i will allow people to use loadFile within functions, but i will encourage people to use preprocessFile because it will be faster.

This is fairly advanced stuff i suppose, so i apologise if i am confusing people.  ::)
Bohemia Interactive Simulations

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #26 on: 08 Jan 2003, 05:03:54 »
its ok  ;D

i just change da loadfiles to preprocessFile nywere its not a prob  ;)

nd i do understand dat - just need 2 write it plain  ;)  ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Pandoz

  • Guest
Re:BETA: OPFEC Function Reference
« Reply #27 on: 08 Jan 2003, 06:50:51 »
hmm i think if some1 knowledgable on this subject *cough*snypir*end cough*:) should write a tutorial that explains the basics and stuff like that...even though the func ref page kinda already explains that...well just write a short one please and maybe give some examples of things u could  do or something...i believe i get it but i am always thinking that and many-a-times i am really wrong.

Pandoz

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #28 on: 08 Jan 2003, 10:23:58 »
Ok, i hope this is basic enough:

http://www.ofpec.com/editors/tutorial_view.php?id=149

It is not complete, but it is a start. Let me know if any part is not clear, ok?

 ;D
Bohemia Interactive Simulations

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #29 on: 08 Jan 2003, 13:30:04 »
LCD: You can now link functions via the submit function screen, and they will be visible in the display view.

KTottE: You can now upload an optional example mission zip in addition to the sqf file.

I think we are getting close to final, once i write up the rules...  ;D

Thanks for all the help dudes - if there are any more suggestions, please send them my way!
Bohemia Interactive Simulations