Jump to content
Sign in to follow this  
kutya

Eventhandlers

Recommended Posts

I used to create units in OFP similar to this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierWB" createUnit [getpos player, _currGroup, "this addeventhandler [{killed} , {_this exec {GDC_events\GDC_FrInfDied.sqs}}]", 1, "PRIVATE"]

In AA, it reports an error here: "this |#|addeventhandler", saying that string is expected instead of code.

I don't know what to do. Tried many things, but no success. Can someone help?

Share this post


Link to post
Share on other sites

then try to rewrite it so you have a string instead of code:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierWB" createUnit [getpos player, _currGroup, "this addeventhandler [""killed"" , {_this exec ""GDC_events\GDC_FrInfDied.sqs""}]", 1, "PRIVATE"]

...but to tell you the truth, i am not sure whether i wrote it right, i am more used to this way:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_g = createGroup "West";

_u = _g CreateUnit ["SoldierWB", _pos, [], 0, "NONE"];

[_u] Join _g;

_eh = _u addEventHandler ["killed", {_this exec "GDC_events\GDC_FrInfDied.sqs"}];

Share this post


Link to post
Share on other sites

You're calling the script with a string instead of unit/code (_this --> this), so remove  _  infront of this.

Share this post


Link to post
Share on other sites

Okay, thanks guys.

IFAIK you can't use nested "-s because the parser doesn't know if you're finishing the previous string or trying to make a nested one. I think that's the reason for BIS to implement { and }.

Again, thanks! I'll try out your suggestions.

Share this post


Link to post
Share on other sites
In AA, it reports an error here: "this |#|addeventhandler", saying that string is expected instead of code.

I think the problem is related to the quotes you are using.

Quotes are used for strings, but you need brackets here as you are using code.

So try {this .... } instead of "this ...",

Share this post


Link to post
Share on other sites

Okay, I'll try this. Thanks.

BTW (_this --> this) didn't work.

Currently I'm using the solution to split the command into multiple lines as 5133p39 described.

Share this post


Link to post
Share on other sites
BTW (_this --> this) didn't work.

Well, as I see the problem it should work. Look where lies the problem:

"this addeventhandler [""killed"" , {_this exec ""GDC_events\GDC_FrInfDied.sqs""}]"

thou I doubt this is the real/only reason for the eventhandler not to work, I think it's more because of those quotations you're over and not correctly using.

Put this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventhandler ["killed" , "this exec {GDC_events\GDC_FrInfDied.sqs}"]

and I'm sure it will work.

Share this post


Link to post
Share on other sites

Okay, will try. When I get home.

Share this post


Link to post
Share on other sites

That won't work if you're trying to pass the eventhandler-_this, not the unit-this. _this is a private array in the eventhandler's scope and has the info about that single particular event.

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  

×