Jump to content
Sign in to follow this  
forzajuve

scriptdone

Recommended Posts

how do I use scriptdone? I'm really not sure where to put it. It seems like it would be good to use as condition for a trigger but that doesn't work. I tried to put it in on act for a trigger but that didn't really seem to do anything besides re-start the script it was supposed to be checking is done.

Share this post


Link to post
Share on other sites

ScriptDone just checks if the script/function with the specified ID has already returned.

So you have to get the ID first and then you can use it in the condition field of any trigger.

myScriptID = 0;

myFunction = {
   hint "Hello world!";
};

myScriptID = [some,variables,to,pass] execVM "someSQF.sqf";
// or
myScriptID = [some,variables,to,pass] spawn myFunction;

And in your trigger's condition field:

this && scriptDone myScriptID

But the thing is: if you place the trigger in the editor, the trigger will be created upon server start and will repeatedly ask for myScriptID to be done.

If you don't execute your script before the trigger is placed, either errors will occur or some other, unwanted behavior.

So what you might have to do is waiting for the script to be done in a script and not in a trigger. If you want to end the mission or do smth else with your trigger,

you could use a global variable to fullfill the cond. of your trigger.

myScriptDone = false;
_myScriptID = [some,variables,to,pass] execVM "someSQF.sqf";

_myScriptID spawn {
   waitUntil {myScriptDone = scriptDone _this; myScriptDone;};
};

And in the cond. field of your trigger:

myScriptDone && this

// edit:

I just realized that my second example has the same problem like the first one: myScriptDone is not defined till the script has run, so the condition of the trigger will check if myScriptDone is true although this variable doesn't exist for some while.

In retrospect, using the second example is less "dangerous" because we deal with a boolean value and not with arma commands.

Edited by XxAnimusxX

Share this post


Link to post
Share on other sites

hmm ok makes sense I guess. except what do I do with the first code?? i.e. where do I put it and where do I get the ID?

---------- Post added at 00:51 ---------- Previous post was at 00:50 ----------

also if I wanted only the script to be done for a condition I could just use

scriptDone myScriptID  

this would just be used for a trigger switch on a hold waypoint

Share this post


Link to post
Share on other sites

Where you get the ID? The ID equals the script handle, which is contained in the return value of every execVM and spawn invocation.

My first code-box shows how the return value of execVM is saved in a global variable named "myScriptID". It has to be global so you can use it in conjunction with triggers.

Where you should put the code?

How should I know? :D

I don't even know for what purpose you need this kind of knowledge so I'm delivering you the basic knowledge you need to put something together on your own :)

I just evaluated it for myself and yes, using "scriptDone myScriptID" in a triggers condition really works and triggers when the script you're waiting for is done.

Share this post


Link to post
Share on other sites

Still not working.

What I need to do: So a player with 2 AI squads goes to a village and the player's squad talks to villagers who tell them where to go. However the 2 AI squads must wait for the chat script to finish otherwise it would be strange if they ran off to the next waypoint before being told where to go.

I tried both of the scripts you posted there, I'm using the first one currently.

First I made a blufor present trigger over the player and squads, which executes

[] exec "wait.sqf";

at the very start of the game.

wait.sqf =

myScriptID = 0;

myFunction = {};

myScriptID = [some,variables,to,pass] execVM "chat1.sqs";
// or
myScriptID = [some,variables,to,pass] spawn myFunction;  

then for the switch trigger that will hold the ai squads until the script is completed

condition:

this && scriptDone myScriptID 

basically it's doing nothing... the AI squads aren't moving and it's executing the first line of the chat script as soon as the mission starts and that's it.

Share this post


Link to post
Share on other sites

Oh, okay, you took my example a bit too serious :D

Change your blufor trigger's activation field to this:

waitForChat = [] execVM "chat1.sqf";

And the condition of the other trigger to:

this && scriptDone waitForChat

You don't need to reroute using a script-file this way. I hope you made a typo with "chat1.sqs", because in this case you'd have to use "exec" and not "execVM".

That and if you use a sqs-file you can't use scriptDone because "exec" doesn't return a script handle.

Share this post


Link to post
Share on other sites

all my chats are .sqs because it makes it easy for chat with ~2, ~5, etc to make the wait in between chat easy. though I always use [] exec "chat.sqs" in a trigger. not too hard to change the few that I need to change to .sqf though and the triggers. I'll try that now and see how it works.

---------- Post added at 21:39 ---------- Previous post was at 21:37 ----------

if I had to use it more than once in a mission on different scripts I would use waitforchat2,3 etc or anything just the change the name of that right?

Share this post


Link to post
Share on other sites

exactly, if you want to wait for a specific script, you have to give it a specific name, if you use the same name altogether the triggers will just wait for one of the scripts to return.

Share this post


Link to post
Share on other sites

not working :/

just started the chat at the start of the mission.

chat: - on act

null = []execVM "chat1.sqf";

wait trigger: - condition

this && scriptDone waitForChat 

blufor: - on act

waitForChat = [] execVM "chat1.sqf"; 

Edited by ForzaJuve

Share this post


Link to post
Share on other sites

There could be another way to do this without using scriptDone.

Add a line at the start of your chat script something like:

FZJ_chatDone = false;

(assuming your tag would be something like "FZJ").

The last line in the chat script needs to be

FZJ_chatDone = true;

You may need an appropriate "sleep" before that line so that FZJ_chatDone cannot return "true" before the chat has finished. Easy enough to test & determine what sleep might be necessary - start the chat script with a radio trigger and time it.

Then the wait trigger condition would become

this && FZJ_chatDone;

Share this post


Link to post
Share on other sites

shit man it actually worked!!! thankyou!!!!!!!!!!!!!!!!!!

thanks also to animus too :p

Share this post


Link to post
Share on other sites

I always try the simplest solution first (well, with my coding skills it's often the only option :) )

It's an approach that MadRussian recommended to me when I was having trouble getting multiple DAC zones to initiate correctly.

If you don't have a tag, go to OFPEC & register one. Using a tag as a prefix will, amongst other things, make such 'control variables' easy to find even in a complex set of scripts even if you've forgotten what you named some of them.

Share this post


Link to post
Share on other sites
I always try the simplest solution first (well, with my coding skills it's often the only option :) )

It's an approach that MadRussian recommended to me when I was having trouble getting multiple DAC zones to initiate correctly.

If you don't have a tag, go to OFPEC & register one. Using a tag as a prefix will, amongst other things, make such 'control variables' easy to find even in a complex set of scripts even if you've forgotten what you named some of them.

what do you mean by this? like FZJ?

Share this post


Link to post
Share on other sites

Yes. My tag is "ORC". You need a tag especially if you want to release an addon or mod, etc., but as indicated it has other uses. Registering a tag with OFPEC means it is allocated to you, and people cannot register duplicate tags. This prevents potential confusion.

Well worth registering yourself on OFPEC anyway, it's a very good resource and has some very competent members active in the forums.

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  

×