Page 1 of 2 12 LastLast
Results 1 to 10 of 13

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

Thread: Converting string value to object name!

  1. #1
    I'm writing a weapon purhcase menu. Problem: lbdata and lbsetdata only store text strings. My code basically checks what the user's selection is, and then grabs the price/name of the weapon/item from an array of the same name.

    init.sqs defines all weapon arrays in format primaryweaponname = [displayname,price,weaponname,magazinename]
    player selects M16 primary weapon
    value of that option is read in and returned (m16)as "primaryweapon"
    cashtemp then subtracts the value of primaryweapon select 1


    This would all work great except for the fact that lbsetdata can only store a string in the dialog options, so when the primaryweapon is returned, it tries to use the string as an arry.

    *shoots flashpoint*

    Is there ANY command available to change the value of a variable from string to object? Or parse a string variable into a variable with type object/array?

    Help?!

    The Captain
    AI Grenadier Aiming Fix
    Close Assault: Company level team vs. team game mode for 32 players.

  2. #2
    </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _sel = lbCurSel _idc
    _obj = lbData &#91;_idc, _sel&#93;
    _com = format &#91;&#34;tmp = %1&#34;, _obj&#93;
    _com foreach &#91;0&#93;

    _yourObject = tmp
    [/QUOTE]<span id='postcolor'>

    As soon as patch 1.85 is out you may change tmp to _tmp so there is no global variable problem.

  3. #3
    Gunnery Sergeant
    Join Date
    May 10 2002
    Location
    That's my business! :p
    Posts
    436
    </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (The_Captain @ Oct. 14 2002,04:57)</td></tr><tr><td id="QUOTE">I&#39;m writing a weapon purhcase menu. Problem: lbdata and lbsetdata only store text strings. My code basically checks what the user&#39;s selection is, and then grabs the price/name of the weapon/item from an array of the same name.

    init.sqs defines all weapon arrays in format primaryweaponname = [displayname,price,weaponname,magazinename]
    player selects M16 primary weapon
    value of that option is read in and returned (m16)as "primaryweapon"
    cashtemp then subtracts the value of primaryweapon select 1


    This would all work great except for the fact that lbsetdata can only store a string in the dialog options, so when the primaryweapon is returned, it tries to use the string as an arry.

    *shoots flashpoint*

    Is there ANY command available to change the value of a variable from string to object? Or parse a string variable into a variable with type object/array?

    Help?&#33;

    The Captain[/QUOTE]<span id='postcolor'>
    Ah yes, for thy i too did so. You see, it was an artillery script which foresook my pitiful death - a death for which i saw no escape. Until some kind members of the underworld - also known as chain of command - rest their sweet brains on my shoulder, and they too solved my queries with this very formula.



    PEACE

  4. #4
    Did not know this trick was possible, it&#39;s awesome&#33;&#33;&#33;
    Who&#39;s puzzled brain has created this? :
    "Well, I need a command which execute Strings. Foreach do execute a string. So let&#39;s use Foreach [0]......"

    /me bows humbly....
    Whisper.
    OFrP member : http://ofrp.free.fr

  5. #5
    Gunnery Sergeant
    Join Date
    May 10 2002
    Location
    That's my business! :p
    Posts
    436
    Using all the power of my brain, i can inaccurately predict that Dinger and Spinor where the genious-es behind this.

    PEACE

  6.   This is the last Developer post in this thread.   #6
    BI Developer Suma's Avatar
    Join Date
    Jun 27 2001
    Location
    Czech Republic
    Posts
    3,707
    4--></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bigpoppa @ Oct. 14 2002,114)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _sel = lbCurSel _idc
    _obj = lbData &#91;_idc, _sel&#93;
    _com = format &#91;&#34;tmp = %1&#34;, _obj&#93;
    _com foreach &#91;0&#93;

    _yourObject = tmp
    [/QUOTE]<span id='postcolor'>

    As soon as patch 1.85 is out you may change tmp to _tmp so there is no global variable problem.[/QUOTE]<span id='postcolor'>
    No, it will not work in 1.85 with _tmp, as _tmp will be created in of forEach scope. You need to introduce _tmp in outer scope first:

    </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _sel = lbCurSel _idc
    _obj = lbData &#91;_idc, _sel&#93;
    private &#34;_tmp&#34;
    _com = format &#91;&#34;_tmp = %1&#34;, _obj&#93;
    _com foreach &#91;0&#93;
    _yourObject = _tmp
    [/QUOTE]<span id='postcolor'>

    Instead of forEach trick you may also use new command call:

    </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _sel = lbCurSel _idc
    _obj = lbData &#91;_idc, _sel&#93;
    private &#34;_tmp&#34;
    call format &#91;&#34;_tmp = %1&#34;, _obj&#93;
    _yourObject = _tmp
    [/QUOTE]<span id='postcolor'>

    You may also rewrite it to use less variables:

    </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    private &#34;_yourObject&#34;
    call format &#91;&#34;_yourObject = %1&#34;, lbData &#91;_idc, lbCurSel _idc&#93;&#93;
    [/QUOTE]<span id='postcolor'>



    Ondrej Spanel, BIS Lead Programmer

  7. #7
    Gunnery Sergeant
    Join Date
    May 10 2002
    Location
    That's my business! :p
    Posts
    436
    Is this a glimpse at to what 1.85 has to offer? Nice...

    PEACE

  8. #8

  9. #9
    Thanks for the hints Suma&#33; The Call.command was something I was waiting for&#33;

  10. #10
    How I can do with "call format"

    Call format [" _TempSetAction = "[%1] exec "Gfolder&#92;CallGroup.sqs"; closedialog 0" ",_i ]
    buttonSetAction [200000 +_j , _TempSetAction]

    ?

    And with foreach I execute a "script" store in edit control

    ctrlText 109 foreach [0]

    ?

    How make a filter for numbers?
    How solve problem with big numbers (scientific notation)?

Page 1 of 2 12 LastLast

Posting Permissions

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