Jump to content
Sign in to follow this  
Ruckus

Passing a Trigger Name to a Script

Recommended Posts

Hi,  I'm trying to pass the name of a trigger to a script and then convert the trigger name to a string to print it out in a hint.  I'm calling this script like:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[Zone1]exec "script.sqs" Zone1 is the name of the trigger in this case.

How can I convert this Zone1 name and convert it to string so I can display it?

Thanks in advance.

Share this post


Link to post
Share on other sites

You can't, AFAIK. Consider going about it the other way - by feeding your script the trigger name instead. One could imagine using

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">["Zone1"] exec "script.sqs"

and then, within "script.sqs" have something like

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_triggerName=_this select 0;

_trigger = call compile _triggerName;

Share this post


Link to post
Share on other sites

Thanks Killswitch, I was afraid that was the case. I tryed several different ways using call and compile, but couldn't get it to work.

I'm doing other things with the trigger name in the script as other triggers also call this script. I would hate to have to call it by using [zone1,"zone1"]exec "script.sqs" as it is a bit redundent.

Share this post


Link to post
Share on other sites

As Killswitch suggests, the best I could come up with was one way traffic (last tried to do it in OFP mind you). On the bright side, having the string of variable names can makes debugging a little easier.

Share this post


Link to post
Share on other sites

Thanks for your replys.

@T_D I'll have to give this a try when I get home.

Thanks again biggrin_o.gif

Share this post


Link to post
Share on other sites

If vehiclevarname does not work and you have a pre-defined number of triggers at the start of you mission, what about:

In your init.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">TRIGGER_ARRAY=[Zone1,"Zone1",Zone2,"Zone2",Zone3,"Zone3"];

In Script.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Trigger=_This Select 0;

_Name="";

_Index=_Trigger Find TRIGGER_ARRAY;

If (_Index!=-1) Then {_Name=TRIGGER_ARRAY Select (_Index+1)}

Share this post


Link to post
Share on other sites

Call me bonkers but I find:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_myTrigger = _this select 0;

_myTriggerName=format["%1", _myTrigger];

Generally gets me the trigger name; unfortunately if this is a trigger created from script as oppose to using the editor , then sometimes the name is a little bonkers , and more often than not contains a space - which really causes problems.

--

At the risk of being accused of hijacking the thread can anyone do the reverse.... ? Create a trigger in script with a predetermined name.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_myTriggerName=format["Trigger%1",triggerNum];

_trigger=createTrigger ["EmptyDetector", _pos];

// the setTriggerName function does not exist...

_trigger SetTriggerName _myTriggerName;

People are probably going to ask WHY do I need to name my trigger ...? The answer is because I'm going to refer to it by name in the condition of a waypoint...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_waypoint=createWaypoint [ gameLogic,0];

_waypoint setWayPointCondition[ format["count list %1 >0",_triggerName];

I've even tried things like

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_cmd=format "%1=createTrigger[""EmptyDetector"",%2];publicVariable "%1";%1",_triggerName,_position];

_compiledCmd=compile _cmd;

_trigger=call _compiledCmd;

to create the trigger with limited sucess...

BA

Share this post


Link to post
Share on other sites
Quote[/b] ]Call me bonkers but I find:

Code Sample  

_myTrigger = _this select 0;

_myTriggerName=format["%1", _myTrigger];

Generally gets me the trigger name

I just did a quick check in the editor with a regular trigger set to BLUFOR present, with the name as test. When I tried this line:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format ["%1 %2",Test,VehicleVarName Test]

It returned:

Quote[/b] ]5129 <no shape>

As you can see I also tried using the vehicle var name command to, with no luck.

Not going to call you bonkers, as it was just a quick test. There may be other conditions or types of trigger that do return the name?

Share this post


Link to post
Share on other sites

Damn, ignore me I'm talking @!$£.

Sorry it works for vehicles and units but NOT for triggers. My sincere apologies for leading you astray.

From what I can see triggers do not have names like units and vehicles; the name is just the name of a variable which points to the trigger.

The best I can suggest is use a an empty object such as a road-cone near the trigger to hold the name. Then use nearestObject to find the nearest object of type road-cone to the trigger, and then use the name of the road-cone.

Its fugly but it will work.

BA

Share this post


Link to post
Share on other sites
Quote[/b] ]Sorry it works for vehicles and units but NOT for triggers. My sincere apologies for leading you astray.

No worries, It's all a little confusing. I saw the same results as you did with vehicles. But even then, it's not so clear cut. I posted a question on the wiki. Perhaps all will become clear over time.

Share this post


Link to post
Share on other sites

Thanks for your replys. I tried some of the suggestions and got the same results as you had.

I tried a different way that was suggested which was to just pass the "Zone1" name text in the array to the script instead of just using the Zone1 trigger name. That way I can access the Trigger with funtions using a call and format as well as work with the text for display.

Again, thanks for the suggestions and help biggrin_o.gif

Share this post


Link to post
Share on other sites
Thanks for your replys. I tried some of the suggestions and got the same results as you had.

I tried a different way that was suggested which was to just pass the "Zone1" name text in the array to the script instead of just using the Zone1 trigger name. That way I can access the Trigger with funtions using a call and format as well as work with the text for display.

Again, thanks for the suggestions and help biggrin_o.gif

What I can't get over is that a trigger has a text property which would be exactly what you need.

Can I find ANY way to read this or other trigger properties...

No

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  

×