Results 1 to 10 of 10

  Click here to go to the first Developer post in this thread.  

Thread: Problem with variable types

  1. #1
    I tried combining names in a script as follows

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    target=&#34;v&#34;+format&#91;&#34;%1&#34;,raah&#9 3;
    [/QUOTE]
    raah is an integer from 1 ... 10
    I then have 10 different objects in a mission named from v1 .. v10

    I then checked that the combining of the number and letter is correct in hint dialog

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format&#91;&#34;%1&#34;,target&#93;[/QUOTE]

    When I try to use the "target" variable in another command I get an error message about the variable being a string and not object.

    So my question is can I change a type of a variable from string to object? Or are there any other possibilities to achieve the same

  2. #2
    Private First Class
    Join Date
    Apr 19 2003
    Location
    Norway, Bergen
    Posts
    27
    dont know exactly but u cant try
    Quote Originally Posted by [b
    Quote[/b] ]_targetname = format ["T72"]



    Server @ hakon.sytes.net port 2304
    <a href=\"http://home.no.net/mrhakon/flashpoint/serverquery205/serverqueries.php/\" target=\"_blank\">Querry
    <a href=\"http://home.no.net/mrhakon/flashpoint/ofpstat/ofp.php\" target=\"_blank\">Server stats

  3. #3
    Private First Class
    Join Date
    Apr 19 2003
    Location
    Norway, Bergen
    Posts
    27
    forgot then u

    [QUOTE]hint format["%1",_targetname]

  4. #4
    Quote Originally Posted by (TheMcDeth @ Jan. 13 2004,07:34)
    I tried combining names in a script as follows

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    target=&#34;v&#34;+format&#91;&#34;%1&#34;,raah&#9 3;
    raah is an integer from 1 ... 10
    I then have 10 different objects in a mission named from v1 .. v10

    I then checked that the combining of the number and letter is correct in hint dialog[/QUOTE]

    Why concatenate strings that way?

    This is better code.
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _target = format&#91;&#34;v%1&#34;, raah&#93;
    hint _target
    [/QUOTE]

    And

    then use

    object _target

    to create an object reference. If that doesn&#39;t work, you&#39;re screwed



    Scott \"Tracy\" T
    Scotland\'s silver tongued cavalier ?

    Author of the original zombie addon!!
    And other shite

    I play online as [TM]Spetsnaz[MAJOR] - don\'t shoot me!!

  5. #5
    Thanks. I have to try it when I get back home in the evening. I thought there must be easier way than what I was trying.

  6. #6
    Use the call command to return the value of a variable from a string. I think it works like this:

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

    _Target=format&#91;&#34;v%1&#34;,raah&#93;

    _CurrTarget=Call {_Target}

    [/QUOTE]

    So if raah equals 1 then _Target="V1". The call command executes a function that returns the value assigned to
    the variable V1.

  7.   This is the last Developer post in this thread.   #7
    BI Developer Suma's Avatar
    Join Date
    Jun 27 2001
    Location
    Czech Republic
    Posts
    3,708
    I think what you mean is more like:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Target=format&#91;&#34;v%1&#34;,raah&#9 3;
    _CurrTarget=call _Target
    [/QUOTE]

    _Target is a string and if you enclose it in double quotes, the result of evaluation will be value of _Target (the string), not the object with the name given in _Target.
    Ondrej Spanel, BIS Lead Programmer

  8. #8
    So to summarise:

    use

    object _varname

    to get an object reference

    and

    call _varname to get the value of a "calculated" named variable at run time.

    Might be one for the FAQ, this?

  9. #9
    Not to beat a dead horse, but this is a single line format I use quite often when needed (using first posts vars):

    call format["target = v%1",raah]

    EDIT: Must mention that "target" variable MUST be declared prior to this line being executed for it to remain in top scope level --- example again:

    target = objNull
    .
    .
    {bunch of code}
    .
    .
    call format["target = v%1",raah]




  10. #10
    Thanks to all who helped me. I reduced the length of one code to about 15 % of the original. When I use the same code in many missions I now have a very easy job of editing the code for each mission.

Posting Permissions

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