Jump to content
Samcot

[SOLVED] Need help with activating a trigger when conversation script has finished running.

Recommended Posts

Hello everyone! Thanks for answering all my questions over the past few days. You have helped me a lot. However, I have another question...

 

I'll start by putting this code which lives inside my Officer unit's init. (Incase anybody needs to see it)

inspector = this addAction[ "Talk to the officer", {  
 params[ "_target", "_caller", "_ID" ]; 
  
 [ "task1", "SUCCEEDED" ] call BIS_fnc_taskSetState; 
  
 [[ 
  [ "CDF Officer", "Welcome to Altis, Captain. We're glad your here.", _target ],  
  [ "Michael", "Glad to be here. So what's the situation?", _caller ],  
  [ "CDF Officer", "The reds have been hitting our supply lines from the east to try and cripple us.", _target ],  
  [ "CDF Officer", "So far we're holding them off in the south but we're noticing their strength increase by the day.", _target ],  
  [ "Michael", "Just keep doing what you're doing and hold firm Sir. Is my lift ready?", _caller ],  
  [ "CDF Officer", "Your carriage awaits, Captain. Board the helicopter when you're ready.", _target ] 
 ], "CUSTOM", 0.10, true ] execVM "fn_simpleConv.sqf"; 
  
 _target removeAction _id; 
}];

The above code lets my player do the following: Speak to the officer > Complete task1 > Then finally run a conversation script. (All working perfectly)

 

I would now like to create a second task (task2) using the BIS "Create Task" module, where my player is told to get into a helicopter.

I tried to create a trigger synced to task2 module with the following code in "Condition"

scriptDone fn_simpleConv;

But this did not work. 

 

Does anybody know a simple way for task 2 to run as soon as my conversation script has finished doing its stuff? (Maybe a 3 second delay after?)

 

Thanks in advance! 

Share this post


Link to post
Share on other sites
8 hours ago, Samcot said:

I tried to create a trigger synced to task2 module with the following code in "Condition"

You can do it easier.

condition:

!isNil "SAM_FirstConversationDone"

 

at end of your conversation script:

SAM_FirstConversationDone = true

I don't know what fn_simpleConv is, but I would recommend adding a parameter to it, with a script that will be executed at the end of the conversation.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Dedmen said:

You can do it easier.

condition:


!isNil "SAM_FirstConversationDone"

 

at end of your conversation script:


SAM_FirstConversationDone = true

I don't know what fn_simpleConv is, but I would recommend adding a parameter to it, with a script that will be executed at the end of the conversation.

 

Looks great. I'll give this a go.

 

fn_simpleConv.sqf is the name of my conversation script. 

 

Thanks for the reply :)

Share this post


Link to post
Share on other sites

@Dedmen It didn't work. I'm not sure I did it right.

 

I added SAM_FirstConversationDone = true at the end of my script in officer's init box. (See bottom of picture)

inspector = this addAction[ "Talk to the officer", {  
 params[ "_target", "_caller", "_ID" ]; 
  
 [ "task1", "SUCCEEDED" ] call BIS_fnc_taskSetState; 
  
 [[ 
  [ "CDF Officer", "Welcome to Altis, Captain. We're glad your here.", _target ],  
  [ "Michael", "Glad to be here. So what's the situation?", _caller ],  
  [ "CDF Officer", "The reds have been hitting our supply lines from the east to try and cripple us.", _target ],  
  [ "CDF Officer", "So far we're holding them off in the south but we're noticing their strength increase by the day.", _target ],  
  [ "Michael", "Just keep doing what you're doing and hold firm Sir. Is my lift ready?", _caller ],  
  [ "CDF Officer", "Your carriage awaits, Captain. Board the helicopter when you're ready.", _target ] 
 ], "CUSTOM", 0.10, true ] execVM "fn_simpleConv.sqf"; 
  
 _target removeAction _id; 
}]; SAM_FirstConversationDone = true;

I then added this to my trigger condition.

!isNil "SAM_FirstConversationDone"

 But it didn't do anything. 

 

I'm sorry if I've done this completely wrong. I have no idea how to add code to a script because I get confused where it should go in relation to all the [ and { brackets.

Share this post


Link to post
Share on other sites

You are almost there.  I would try the following:

 

1. In your init.sqf add this:

SAM_FirstConversationDone = false; // initialize global variable to false.

2. As you have already done, set SAM_FirstConversationDone = true; at the end of your script.

3. Change your trigger condition to read like this:

SAM_FirstConversationDone

There would be no quotes around the global variable name in this case.  It is a simple boolean variable which is either true or false.

 

Good luck, and welcome to script-o-mania.

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, johnnyboy said:

You are almost there.  I would try the following:

 

1. In your init.sqf add this:


SAM_FirstConversationDone = false; // initialize global variable to false.

2. As you have already done, set SAM_FirstConversationDone = true; at the end of your script.

3. Change your trigger condition to read like this:


SAM_FirstConversationDone

There would be no quotes around the global variable name in this case.  It is a simple boolean variable which is either true or false.

 

Good luck, and welcome to script-o-mania.

 

Thanks for the reply @johnnyboy.

 

Unfortunately it still isn't working 😞 

Share this post


Link to post
Share on other sites

Hmmm.  Try moving SAM_FirstConversationDone = true;   to inside your addAction code like this.  The way you have it now now, the variable is set to true immediately after the action is added, rather than after the conversation script runs.

Spoiler

inspector = this addAction[ "Talk to the officer", {  
 params[ "_target", "_caller", "_ID" ]; 
  
 [ "task1", "SUCCEEDED" ] call BIS_fnc_taskSetState; 
  
 [[ 
  [ "CDF Officer", "Welcome to Altis, Captain. We're glad your here.", _target ],  
  [ "Michael", "Glad to be here. So what's the situation?", _caller ],  
  [ "CDF Officer", "The reds have been hitting our supply lines from the east to try and cripple us.", _target ],  
  [ "CDF Officer", "So far we're holding them off in the south but we're noticing their strength increase by the day.", _target ],  
  [ "Michael", "Just keep doing what you're doing and hold firm Sir. Is my lift ready?", _caller ],  
  [ "CDF Officer", "Your carriage awaits, Captain. Board the helicopter when you're ready.", _target ] 
 ], "CUSTOM", 0.10, true ] execVM "fn_simpleConv.sqf"; 
  
 _target removeAction _id; 
 SAM_FirstConversationDone = true; // PUT THIS *INSIDE* ADDACTION CODE BRACKETS!
}]; 

 

 

  • Like 3

Share this post


Link to post
Share on other sites
12 minutes ago, johnnyboy said:

Hmmm.  Try moving SAM_FirstConversationDone = true;   to inside your addAction code like this.  The way you have it now now, the variable is set to true immediately after the action is added, rather than after the conversation script runs.

 

Hmm, still not working. The script seems perfect I don't know why it won't activate the trigger. Perhaps I'm doing something wrong with the trigger.

I read somewhere that triggers don't like booleans. So I changed the code in init.sqf to conv1 = 0; // Initialize global variable to false. Then I added conv1 = 1; into my addAction script like you showed me above. (Also changed name to conv1 to keep it shorter).

 

Here is a screenshot of my trigger.

 

And here is the addAction code. 

inspector = this addAction[ "Talk to the officer", {   
 params[ "_target", "_caller", "_ID" ];  
   
 [ "task1", "SUCCEEDED" ] call BIS_fnc_taskSetState;  
   
 [[  
  [ "CDF Officer", "Welcome to Altis, Captain. We're glad your here.", _target ],   
  [ "Michael", "Glad to be here. So what's the situation?", _caller ],   
  [ "CDF Officer", "The reds have been hitting our supply lines from the east to try and cripple us.", _target ],   
  [ "CDF Officer", "So far we're holding them off in the south but we're noticing their strength increase by the day.", _target ],   
  [ "Michael", "Just keep doing what you're doing and hold firm Sir. Is my lift ready?", _caller ],   
  [ "CDF Officer", "Your carriage awaits, Captain. Board the helicopter when you're ready.", _target ]  
 ], "CUSTOM", 0.10, true ] execVM "fn_simpleConv.sqf";  
   
 _target removeAction _id;  
 conv1 = 1;
}];

Also, Here is my create task module. (Create task module is synced to my player. Previously I used "All playable units" for the Owner.)

  • Like 1

Share this post


Link to post
Share on other sites

To test equality, you use two equals signs, like this:

conv1 == 1

A singles equals sign is used for value assignment.  

 

When testing your mission, you can hit escape and see the debug console.  In the section labeled "Watch:" there are four input fields where you can put variables and expressions so you can monitor the values any time while testing the mission.  Put conv1 in one of these watch fields.  Now run your mission. As soon as mission has started and is playable, press escape and see what value of conv1 is.  Hopefully it starts off as 0 (zero) if you initialized it in your init.sqf.  Then play your mission to point where the Action is added to officer.  Press Escape again.  The conv1 value should still be zero.  Return to mission and execute the conversation action on the officer.  After the conversation occurs, press escape again.  At this point, we hope the value of conv1 is now 1.

 

This is a basic debugging approach, and i hope it helps.

 

I would also put this code in the trigger in the onActivation box:

hintc "My trigger fired so conv1 must equal 1 now.  Yoda be praised.";

This makes it clear your trigger fired.

 

I'm not familiar with the module.  But if you do the above we will have narrowed down your problem.  Maybe the variable is working and the trigger fires, but there is no linkage to the module.  I can't tell.

  • Like 4

Share this post


Link to post
Share on other sites
18 minutes ago, johnnyboy said:

To test equality, you use two equals signs, like this:


conv1 == 1

A singles equals sign is used for value assignment.

 

When testing your mission, you can hit escape and see the debug console.  In the section labeled "Watch:" there are four input fields where you can put variables and expressions so you can monitor the values any time while testing the mission.  Put conv1 in one of these watch fields.  Now run your mission. As soon as mission has started and is playable, press escape and see what value of conv1 is.  Hopefully it starts off as 0 (zero) if you initialized it in your init.sqf.  Then play your mission to point where the Action is added to officer.  Press Escape again.  The conv1 value should still be zero.  Return to mission and execute the conversation action on the officer.  After the conversation occurs, press escape again.  At this point, we hope the value of conv1 is now 1.

 

This is a basic debugging approach, and i hope it helps.

 

I would also put this code in the trigger in the onActivation box:


hintc "My trigger fired so conv1 must equal 1 now.  Yoda be praised.";

This makes it clear your trigger fired.

 

I'm not familiar with the module.  But if you do the above we will have narrowed down your problem.  Maybe the variable is working and the trigger fires, but there is no linkage to the module.  I can't tell.

 

Ok, so I did what you asked. 

 

On mission start the value of conv1 is 1. Even though I set it to 0 in my init.sqf. See below for the contents of my init.sqf.

wp1 = compile preprocessfile "wp1.sqf" ; // Play helicopter path via made with unitCapture.

conv1 = 0; // Initialize global variable to false.

I also added the following to my trigger on act box. 

hint "My trigger fired so conv1 must equal 1 now. Yoda be praised.";

It wouldn't let me do hintc so I presume this was a typo?

The trigger did not seem to fire as I didn't get the hint pop up. 

 

I'm not sure why this isn't working lol. Also thanks for telling me about these handy debug tricks. They will sure come in handy. Also thank you for your patience in dealing with this issue for me :)

  • Like 2

Share this post


Link to post
Share on other sites

@Samcot,

You may need to spawn a little sleep for your HintC,

Spoiler

	[] spawn {sleep 0.5; "Sit-rep" hintC [
	"a little sleepy",
	"makes the HintC appear",
	"there's no comma at the end here"
	];};

also it may be a little poem.


Have fun!
 

  • Like 4

Share this post


Link to post
Share on other sites
2 hours ago, Samcot said:

It wouldn't let me do hintc so I presume this was a typo?

The trigger did not seem to fire as I didn't get the hint pop up. 

 

I'm not sure why this isn't working lol. Also thanks for telling me about these handy debug tricks. They will sure come in handy. Also thank you for your patience in dealing with this issue for me 🙂

No problem dude.  Glad to help out enthusiastic polite people.

 

Use a hint instead of hintc (or do what Wogz suggested).

 

And did you change the trigger condition from conv1 = 1 to conv1 == 1?  Because if you left the trigger condtion as conv1 = 1, then the first time the trigger condition was evaluated by engine, it would set conv1 to 1, which would explain why you saw this value as 1 in the console.  

 

You are close to solving this, don't give up!  🙂

 

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, johnnyboy said:

No problem dude.  Glad to help out enthusiastic polite people.

 

Use a hint instead of hintc (or do what Wogz suggested).

 

And did you change the trigger condition from conv1 = 1 to conv1 == 1?  Because if you left the trigger condtion as conv1 = 1, then the first time the trigger condition was evaluated by engine, it would set conv1 to 1, which would explain why you saw this value as 1 in the console.  

 

You are close to solving this, don't give up!  🙂

 

It worked! Thank you so much! the simple addition of a = sign made all the difference... Bloody scripting eh. I'm motivated now more than ever to learn as much as I can about this.

 

Thanks again :)

  • Like 2

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

×