Jump to content
Sign in to follow this  
Dreepa

Noob question about triggers

Recommended Posts

Hey,

so I am trying hard to get the hang of this all :)

I am making some progress, but for some reason some stuff won't work properly.

For some reason this trigger produces "Error Generic error in expression":

deleteMarker "obj4"; task4 setTaskState "SUCCEEDED"; sleep 10; hint "Data recovered."

But the task is still set to done and the hint "Data recovered" is also shown.

And another trigger that will fire an error message ingame when triggered is:

sleep 20; task3 = player createSimpleTask ["Survive"]; task3 setSimpleTaskDescription ["Your escape route is compromised. Lay low and move south east.", "Survive", "Survive"]; task3 setSimpleTaskDestination (getMarkerPos "obj_3"); hNil = [objNull, ObjNull, tskobj_3, "ASSIGNED"]; hint "Your Tasks have been updated";

I am a bit lost as to what I am doing wrong.

Share this post


Link to post
Share on other sites

You can't sleep nor wait in unscheduled "enviroments" like called functions, eventhandlers or - in this case - the onAct-Field of triggers.

The fastest workaround would be wrapping your code into a spawn:

[] spawn {deleteMarker "obj4"; task4 setTaskState "SUCCEEDED"; sleep 10; hint "Data recovered.";};

Share this post


Link to post
Share on other sites

Thanks!

May I ask for the slower workaround, out of curiousity?

(eager to learn more stuff) :)

Share this post


Link to post
Share on other sites

Hmm personally I don't like too much code in the onAct/Deact-Fields of triggers, it gets confusing the more code you put in.

If I have more than 3 commands, I consider putting those commands into a function and spawning that function in the onAct-Field.

Something like

myTriggeredFunction = {
   deleteMarker "obj4"; 
   task4 setTaskState "SUCCEEDED"; 
   sleep 10; 
   hint "Data recovered.";
};

in any SQF-File or in the init.sqf and putting this into the onAct-field:

thisList spawn myTriggeredFunction;

But this could cause other problems, like you have to define the spawned function for every client (so using init.sqf wouldn't be so bad after all) and other problems stemming from MP locality.

Or you could play around with the timeout/countdown value of the trigger to achieve similar effects? I don't know, could be even more work to do so maybe not :D

It couldn't hurt to think about the need of the trigger in the first place - some cases don't require using them and sometimes it's even better to rely on scripts other than triggers.

My rule of thumb is: Does my script has to detect the presence of something or somebody? If the answer is yes, use triggers, if no, well, roll up your sleeves and get yourself scriptin' :D

Edited by XxAnimusxX

Share this post


Link to post
Share on other sites

Thanks! I also looked spawn up immediatelly. Helps a lot. Thing I go that way first.

It returns a script handle, but in your quote you do not assign that script handle to a name/variable. I saw other examples where people use "Nil" etc. for putting the void. Is that recommended? Or does it not make any difference?

Share this post


Link to post
Share on other sites

Triggers force you to use the return value of any function you call/spawn. Omitting the return value would lead to an error, thus preventing to save your triggers properties.

I also used to assign the return value to nil, which is a keyword to undefine existing variables - but the BIKI suggest or rather warns not to assign any value to nil, which is understandable because this would mean to make a global variable out of nil, corrupting the use of this "keyword".

Just use any global variable name (global means without the _ ) to catch the return value.

Outside of triggers you can just disregard the return value - if you don't need it, why bother creating a variable you'll never use? :D

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  

×