Results 1 to 6 of 6

Thread: Passing unit name to a script that uses @ ***alive

  1. #1
    Master Gunnery Sergeant norrin's Avatar
    Join Date
    Aug 30 2006
    Location
    Melbourne, Australia
    Posts
    1,123
    Hi guys,

    I can't seem to find an answer to this in the scripting tutorials I've down loaded or in the BI forums and with OPFEC still down I'm starting to go a little crazy.

    I'm writing a script that will in effect set multiple waypoints to respawning AI units to use with my progressive respawn script (a discussion of which you can find here). ***

    So far I've managed to do this for individual AI units using the doMove command.

    For instance, I have an AI unit with name set to e1 and have placed the following code in its init line:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {&#91;&#93; exec &#39;Do_Move.sqs&#39;}&#93;;[/QUOTE]

    My basic script for a specific unit looks like this:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#59;Do_Move.sqs&#39;

    #START
    ? &#40;WP_0&#41;&#58; goto &#34;ONE&#34;
    Exit

    #ONE
    @&#33;alive e1
    @ alive e1
    #LOOP
    ;unit moves to 1st waypoint
    e1 doMove &#40;getMarkerPos &#34;Obj_WP_0&#34;&#41;
    @&#40;e1 distance getMarkerPos &#34;Obj_WP_0&#34;&#41; &#60; 1
    ;unit moves to final waypoint
    e1 doMove &#40;getMarkerPos &#34;East_0&#34;&#41;
    Exit[/QUOTE]

    I’ve included the if command at the start of the script as once its all running nicely I intend to have multiple waypoints set to each of my progressive respawn points.

    Where I’m having problems is when I try and generalise this script for a range of AI units named e1, e2 e3 etc.

    In the general script I’ve created a local variable that is meant to take the unit name so I’ve change the script to look like this:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Do_Move.sqs&#39;
    _unit = _this select 0

    #START
    ? &#40;WP_0&#41;&#58; goto &#34;ONE&#34;
    Exit

    #ONE
    @&#33;alive _unit
    @ alive _unit
    #LOOP

    _unit doMove &#40;getMarkerPos &#34;Obj_WP_0&#34;&#41;
    @&#40;_unit distance getMarkerPos &#34;Obj_WP_0&#34;&#41; &#60; 1
    _unit doMove &#40;getMarkerPos &#34;East_0&#34;&#41;
    Exit[/QUOTE]


    Then in each units init field I’ve placed the following code
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {&#91;x&#93; exec &#39;Do_Move.sqs&#39;}&#93;;[/QUOTE] where x is the units name eg e1, e2 etc. ***

    Now for some reason this is not working and the alive command just is not seeing the units name and therefore is not activating. ***

    I’ve tried a variety of syntax including placing the units name in “” in the init line but not surprisingly that just gives me string error with the alive command. ***

    I’m sure I’m missing something very simple here in defining my script variable and then passing it from the init line to my script so any help would be much appreciated.

    **[XDF]*****************************[AAW]**

  2. #2
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {_this exec &#39;Do_Move.sqs&#39;}&#93;;[/QUOTE]
    And within your Do_Move.sqs (_this select 0) will be the name of the unit.

  3. #3
    hmm the " does not look right after init = and should it not be [_x]
    not [x] ? or even more _this . or does a specific unit have different waypoints ? if it dosent then it wont matter if the scipt knows the units name or not i suppose.
    i think to get it to know the units name in order to send e1 to a different waypoint than e2.
    you must use ,(name _unit) = "e1" : goto "e1waypoint"

    #e1waypoint

    or maybe you have too go further and define more.

    _unit = _this select 0
    ?(name _unit) in ["e1"] : goto "e1waypoint"




  4. #4
    Master Gunnery Sergeant norrin's Avatar
    Join Date
    Aug 30 2006
    Location
    Melbourne, Australia
    Posts
    1,123
    Author of the Thread
    Thanks for the suggestions guys I do appreciate your help. ***Although I&#39;m not 100% certain about what your suggesting &#39;cause I&#39;m new to scripting deanosbeano I&#39;ve spent several hours now trying just about every permutation and combination I could think of what you both suggested with no success.

    About an hour into this process I got the idea to place the following statement in the #ONE section of my script to check to see if the variable was defined as the script was running:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?&#40;&#33;isnil &#40;&#34;_unit&#34;&#41;&#41;&#58; hint &#34;_unit defined&#34;[/QUOTE]

    Simply put if the script could detect that a value for the variable _unit had been sent to the script then text would appear on the screen with the message "_unit defined"

    What I found if I changed the init line of the unit to read either this;
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {_this exec &#39;Do_Move.sqs&#39;}&#93;; [/QUOTE]

    or this

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {&#91;_x&#93; exec &#39;Do_Move.sqs&#39;}&#93;; [/QUOTE] (where x is the unit name e1).

    was that no value was being sent to the script for the variable _unit.

    To cut a long story somewhat shorter I also replaced the @&#33;alive and @alive conditions to a wait timer set to 6 secs (ie ~6) so that the script would wait until after the unit had respawned before continuing as <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">respawndelay = 5[/QUOTE] had been set in the description.ext file as I thought that the alive command did not work with the _unit variable (this presumption later turned out to be false and @alive works perfectly well with the _unit variable).

    I next got the great idea to include this statement to check to see whether the variable had not only been defined but also equalled "e1" (the name of my unit I was trying to get to move upon respawning) so I included this after the wait code:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?&#40;&#33;isnil &#40;&#34;_unit&#34;&#41;&#41; AND &#40;_unit == e1&#41;&#58; hint &#34;wait over&#34;[/QUOTE]

    Now what I found when I used:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {&#91;e1&#93; exec &#39;Do_Move.sqs&#39;}&#93;;[/QUOTE]

    In the init line of unit e1 that on e1&#39;s death although the variable was being defined it did not equal e1. ***

    Now this is where it gets really crazy. ***If in another unit I put that exact same code in its init line, for instance for unit e3 I put:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init=&#34;this addEventHandler &#91;&#39;killed&#39;, {&#91;e1&#93; exec &#39;Do_Move.sqs&#39;}&#93;;[/QUOTE]

    When unit e3 dies it not only sends the variable to the Do_Move script it does equal e1 and it causes e1 to run between the two waypoints.

    Therefore it would appear I cannot pass a variable from my init line if that variable is the same as the units name. ***Go figure. ***Has anybody else encountered this as I&#39;m sure I&#39;m missing something simple here? Is there a work around?




  5. #5
    You&#39;re testing for _unit is a double negative.
    It should be if (isNil ("_unit")).... You negate the whole thing by having an exclamation point in front. That&#39;s why it&#39;s saying it&#39;s undefined.

    Your init line should look like this:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler &#91;&#34;killed&#34;, {_this exec &#34;Do_Move.sqs&#34;}&#93;;[/QUOTE]
    And in your script you would then use element 0 of the array you&#39;re passing (_this):
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0[/QUOTE]




  6. #6
    Master Gunnery Sergeant norrin's Avatar
    Join Date
    Aug 30 2006
    Location
    Melbourne, Australia
    Posts
    1,123
    Author of the Thread
    Quote Originally Posted by (Kronzky @ Jan. 22 2007,00:42)
    You&#39;re testing for _unit is a double negative.
    It should be if (isNil ("_unit")).... You negate the whole thing by having an exclamation point in front. That&#39;s why it&#39;s saying it&#39;s undefined.[/code]
    Thanks for the suggestions Kronzky.

    I might have this completely wrong but with the double negative I was trying to get the script to ask whether the variable is defined, not whether the variable is undefined ie. is the variable not null.

    I do notice you have suggested I use double parentheses (ie.") around killed and the script name in the init line rather than the single parentheses (ie. &#39; ) I have used up until this point. Maybe this syntax difference has been having some effect on the sending of the variables to the script?

    Anyway I&#39;ll try changing this in the init line when I get home tonight and I&#39;ll also try replacing the [e1] with _this again as well.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •