Jump to content
Sign in to follow this  
igneous01

preprocess function to call inside init line?

Recommended Posts

I am using a very basic function that I made that allows me to create light sources with basic input on light intensity and color etc. It would be alot easier for me to do this on the init line of an object since I can avoid unnecessary naming of objects and having to use a trigger to call all these lights. I thought that:

 call compile preprocessfilelinenumbers "Functions.sqf"

would allow the function (which is named Fnc_CreateLight) to be called anywhere, including the init line of objects or units. But when I use try to use it for ex:

lobj1 = [ [getpos this select 0, getpos this select 1, 2], [0.0, 0.5, 0.5], 0.05] call Fnc_CreateLight

it does not do anything, when I hinted to see if lobj1 exists (the function returns the light object) it returns as <any>, if I use it in a trigger the light is created as expected.

Is there something I am missing here? I thought I would be able to call the function from the init line if I preprocessed the functions script?

Share this post


Link to post
Share on other sites

this is definitely not correct. Use _this instead... but is it the only problem? I don`t know... it`s too early in the morning for me.. :o

Share this post


Link to post
Share on other sites
this is definitely not correct. Use _this instead... but is it the only problem? I don`t know... it`s too early in the morning for me.. :o

you are right about _this, but is this not used inside scripts? this has always been used in trigger activation lines and init boxes and waypoint activation boxes?

Unless it has changed, I wasn't aware, but this still works inside the editor - maybe too early in the morning? :D

Share this post


Link to post
Share on other sites

this is used in editor fields.

_this yields the parameters within scripts/functions

The problem is probably initialization timing.

Use XEH (Extended EventHandlers) included with CBA (Community Base Addons) to easily work around it, from description.ext (or an addon config):

class Extended_PreInit_EventHandlers {
 class MyMission {
    init = "call compile preprocessfilelinenumbers 'Functions.sqf'";
 };
};

See http://browser.dev-heaven.net/configclasses/config/Extended_PreInit_EventHandlers for examples

Edited by Sickboy

Share this post


Link to post
Share on other sites

you could also just use a spawn in the init waiting for the function to be ready for use.

place a variable = true; at end of the compiled file.

use spawn in init of units or the script that handles the inits.

_null = this spawn {waitUntil {!isNil "variable"}; lobj1 = [ [getpos [b]_this[/b] select 0, getpos [b]_this[/b] select 1, 2], [0.0, 0.5, 0.5], 0.05] call Fnc_CreateLight};

Now every units init will wait for function to be ready, then run as expected.

And as Sickboy pointed out, this is used in editor, and translates to _this inside the spawn.

Share this post


Link to post
Share on other sites
use spawn in init of units or the script that handles the inits.

_null = this spawn {waitUntil {!isNil "variable"}; lobj1 = [ [getpos [b]_this[/b] select 0, getpos [b]_this[/b] select 1, 2], [0.0, 0.5, 0.5], 0.05] call Fnc_CreateLight};

This will fail because you can't use local variables in outer most scope in editor fields.

0 = this spawn ...

would work

But more importantly; Avoid spawn when you can; http://community.bistudio.com/wiki/6thSense.eu:EG#Scripting_Tips

Especially since ARMA 2's script scheduling.

For just a mission with a couple of scripts this should not be noticeable too quickly, however soon enough you build a more advanced mission or start using addons, and it'll build up rather quickly.

Share this post


Link to post
Share on other sites

thanks for the suggestions sickboy and demonized. I think I shall try the XEH since it looks much more cleaner.

ty ;)

Share this post


Link to post
Share on other sites
This will fail because you can't use local variables in outer most scope in editor fields.

0 = this spawn ...

would work

I use _null all the time in outer editor fields, have been for years, never been a issue for me.

It will however not do if you need to reference it with scriptDone command after, wich is bugged somewhat in latest patch anyway.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×