OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bedges on 15 Oct 2005, 10:52:00

Title: which costs more...
Post by: bedges on 15 Oct 2005, 10:52:00
it's maybe a pedantic question considering how fast flashpoint parses scripts, but i'm wondering which is more efficient:


they're arrays of all weapon types and corresponding ammotypes, so they're quite long. they're used by 2 scripts so far.
Title: Re:which costs more...
Post by: THobson on 15 Oct 2005, 12:20:08
I always use local arrays where I can and global only when necessary.

I believe that the time taken to parse a script is irrelevant to performance unless there are thousands of them that are parsed in a short space of time
Title: Re:which costs more...
Post by: Trapper on 15 Oct 2005, 12:26:19
maybe...

Global
 good
 - faster access
 - lower chance of typos
 - later changes are more easy
 - array content can be changed in game by one script for all scripts (global ;) )

 bad
 - always loaded in memory

Local
 good
 - only loaded in memory if needed
 - each script on it's own is easier to understand

 bad
 - same array multiple times in memory if scripts are running simultaneously
 - slower access
 - later changes are more difficult
 - higher chance of typos
 - array content can't be changed in game by one script for all scripts (local ;) )
Title: Re:which costs more...
Post by: bedges on 15 Oct 2005, 12:59:38
hmmm.... how d'you know local arrays are accessed slower than global arrays?
Title: Re:which costs more...
Post by: Baddo on 15 Oct 2005, 13:29:50
hmmm.... how d'you know local arrays are accessed slower than global arrays?

My guess: because a global variable initialized in the start of the mission is already in memory when your script starts but a local variable needs to be initialized first in each script (placed into memory). And additionally, the speed to access array contents after the variable has been placed into memory can also be different for local and global but this can't be said without testing it and it's not what matters here.

It's a guess only from my part. This is the kind of things which can be said for sure only through testing.

I would say, make it global but remember to use your ofpec tag in the variable name.

THobson has a good point there to avoid global variables as much as possible. It's a normal programming way to give the variable a scope it needs, but not any more. In OFP we have to make exceptions sometimes (your global variable in OFP can be accessed from other scripts which don't actually need to access it at all).
Title: Re:which costs more...
Post by: Trapper on 15 Oct 2005, 13:41:29
I don't know it, but I had the same thoughts as Baddo.
Title: Re:which costs more...
Post by: bedges on 15 Oct 2005, 13:45:56
right. some good advice there gentlemen, thankyou  8)
Title: Re:which costs more...
Post by: THobson on 15 Oct 2005, 15:54:12
Test it with several thousand arrays and see if you can tell the difference.