Jump to content

Recommended Posts

Posted (edited)

Hello Everyone,

I am trying to find an easy way for mission end-users to change properties in my mission script without having to interact directly with the .lua file, and I thought that a brilliant way to do this would be to have them change flag values in the mission editor and have the script pull these ME flag values using trigger.misc.getUserFlag(). Here's an example of how I've implemented it in the code:

local exampleValue = trigger.misc.getUserFlag('exampleValue')

The only problem is that this invariably returns 0, even if I set the flag value to the desired value (in this case, 200). I have made sure that the flag is set at mission start in the mission editor, I've made sure there are no typos in both the flag name in the ME and in the code. I checked the documentation on the hoggitworld wiki and the description of the function is "Returns the value of a user flag". After some time trying to troubleshoot, I have come to the conclusion that this function is not supposed to work with the ME flags, but instead it can only interact with flags set via its sister function trigger.action.setUserFlag(). Is this correct, or am I doing something horribly wrong?

If this function isn't meant to allow you to interact with ME flags, then what purpose does it serve? What is a 'user flag'?

 

Sorry if this seems trivial, I have relatively little experience with LUA scripting for DCS World.

Edited by deadyeti
clarification
Posted

Last week i used this function the other way around. Setting a userflag from the script and then using that for a trigger in the mission editor:

trigger.action.setUserFlag( FlagName, true )

the created a trigger that displayed a message based on that flag. So definitely interaction between scriptflags and mission editor flags. I haven't tried it the other way around yet though, but should work just fine unless there is a bug there.

will test it now.

 

Posted (edited)
5 minutes ago, nighteyes2017 said:

Last week i used this function the other way around. Setting a userflag from the script and then using that for a trigger in the mission editor:

trigger.action.setUserFlag( FlagName, true )

the created a trigger that displayed a message based on that flag. So definitely interaction between scriptflags and mission editor flags. I haven't tried it the other way around yet though, but should work just fine unless there is a bug there.

will test it now.

 

Yes, to be clear I was trying to get a number value from the flag. My apologies for not making it clear in the original post. So I want to be able to set flag exampleValue to 200 and be able to retrieve the numerical value with the trigger.misc.getUserFlag() function. I haven't tried getting boolean values, but I suspect that the function is supposed to return number values with 0 and 1 being used as true and false, respectively.

Edited by deadyeti
Posted (edited)

yes i understood that you were trying to GET the flag and not set it. So i'm trying it now. Seeing the same problem. Setting from script and picking it up in the mission editor triggers works fine, just not the other way around.

setting true and testing for 1 is the same thing btw.

Edited by nighteyes2017
Posted
4 minutes ago, nighteyes2017 said:

yes i understood that you were trying to GET the flag and not set it. So i'm trying it now. Seeing the same problem. Setting from script and picking it up in the mission editor triggers works fine, just not the other way around.

setting true and testing for 1 is the same thing btw.

 

I've tried setting the flag value both at mission start and after 10 seconds, both of which have failed. My script isn't trying to get the flag value until 20 seconds after the mission starts, so it's not trying to get the flag value before it is set.

I'm out of ideas, haha. Perhaps it's just a bug.

  • Solution
Posted (edited)

Yeah ok, seems to be working.

trick is how the flag was set from the mission editor.

When using flag on/off, the value is a 1 or 0. when you use an if statement to test the value, you should use a integer or boolean value to test for it, and not the string value.

setting flag random value (max 100) works too.

 

userflag test.miz

Edited by nighteyes2017
Posted
35 minutes ago, nighteyes2017 said:

Yeah ok, seems to be working.

trick is how the flag was set from the mission editor.

When using flag on/off, the value is a 1 or 0. when you use an if statement to test the value, you should use a integer or boolean value to test for it, and not the string value.

setting flag random value (max 100) works too.

 

userflag test.miz 18.12 kB · 1 download

 

I assigned trigger.misc.getUserFlag() directly to a local variable and it now seems to be working as well, strange.
I marked your answer as the solution although I'm still not quite sure what I did wrong, haha. But at least it's working! I'll have to do more research into what I initially did wrong later, I'm going to bed now.

 

Thank you for your help

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...