+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    GeneralCarver's Avatar
    Join Date
    Aug 2007
    Location
    Indiana, USA
    Age
    31
    Posts
    494

    Scripting Trouble - Error Undefined Variable

    I am making my own simple revive script. Long story short, in multiplayer, when AI is disabled, I am getting the Undefined Variable error when my scripts reference the named units which are not being played in the current mission and are not present. If someone is playing the unit, it would work fine. The script below is one of a series of IF statements in the script which find which unit a player is

    if (player == player1) then <------ this is the error, if player1 unit is not used, it will say undefined variable.
    {
    gc_revive_player1needrevive = "true";
    gc_revive_player1active = "false";
    gc_revive_player1oldbody = _oldbody;
    gc_revive_inholding = "true";
    publicvariable "gc_revive_player1needrevive";
    publicvariable "gc_revive_player1oldbody";
    publicvariable "gc_revive_player1active";
    "player1marker" setmarkerpos getpos _oldbody;
    "player1marker" setmarkertext ("" + str name player + " (needs revive)");
    "player1marker" setmarkertype "Dot";
    };

    So, this code works when someone is playing the unit player1. However, if that unit is not used in a multiplayer game, it will return an error "undefined variable". As would be expected, since player1 doesn't exist at the time.

    Can anyone think of a way around this?
    Last edited by GeneralCarver; 12-10-2009 at 07:39 PM. Reason: more to say


  2. #2
    Fincuan's Avatar
    Join Date
    Jan 2009
    Location
    Helsinki, Finland
    Posts
    739

    Re: Scripting Trouble - Error Undefined Variable

    Wrap the whole thing to:
    Code:
    if (not isNil "player1") then
    {
    
    };


  3. #3
    GeneralCarver's Avatar
    Join Date
    Aug 2007
    Location
    Indiana, USA
    Age
    31
    Posts
    494

    Re: Scripting Trouble - Error Undefined Variable

    Quote Originally Posted by Fincuan View Post
    Wrap the whole thing to:
    Code:
    if (not isNil "player1") then
    {
    
    };

    That worked man! Thanks a lot! Case closed!



  4.  
  5. #4

    Dredge's Avatar
    Join Date
    Oct 2009
    Location
    Keying Boons Car
    Age
    25
    Posts
    3,373
    Blog Entries
    5

    Re: Scripting Trouble - Error Undefined Variable

    When is this bad boy being released?
    Last edited by Dredge; 12-11-2009 at 02:36 PM.


  6. #5
    GeneralCarver's Avatar
    Join Date
    Aug 2007
    Location
    Indiana, USA
    Age
    31
    Posts
    494

    Re: Scripting Trouble - Error Undefined Variable

    Probably tonight. I've had to redo part of it to make it better.


  7. #6

    Dredge's Avatar
    Join Date
    Oct 2009
    Location
    Keying Boons Car
    Age
    25
    Posts
    3,373
    Blog Entries
    5

    Re: Scripting Trouble - Error Undefined Variable

    I eagerly await its release......need to put it in the ACE Event Mission...nice little debut me thinks



  8.  

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

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