Jump to content
Sign in to follow this  
The_Captain

Converting string value to object name!

Recommended Posts

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

Share this post


Link to post
Share on other sites

</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 [_idc, _sel]

_com = format ["tmp = %1", _obj]

_com foreach [0]

_yourObject = tmp

<span id='postcolor'>

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

Share this post


Link to post
Share on other sites

</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'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<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.

smile.gif

tounge.gif PEACE

Share this post


Link to post
Share on other sites

Did not know this trick was possible, it's awesome!!!

Who's puzzled brain has created this? wink.gif :

"Well, I need a command which execute Strings. Foreach do execute a string. So let's use Foreach [0]......"

/me bows humbly....

Share this post


Link to post
Share on other sites

Using all the power of my brain, i can inaccurately predict that Dinger and Spinor where the genious-es behind this. tounge.gif

wow.gif PEACE

Share this post


Link to post
Share on other sites

wow.gif4--></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bigpoppa @ Oct. 14 2002,11wow.gif4)</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 [_idc, _sel]

_com = format ["tmp = %1", _obj]

_com foreach [0]

_yourObject = tmp

<span id='postcolor'>

As soon as patch 1.85 is out you may change tmp to _tmp so there is no global variable problem.<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 [_idc, _sel]

private "_tmp"

_com = format ["_tmp = %1", _obj]

_com foreach [0]

_yourObject = _tmp

<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 [_idc, _sel]

private "_tmp"

call format ["_tmp = %1", _obj]

_yourObject = _tmp

<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 "_yourObject"

call format ["_yourObject = %1", lbData [_idc, lbCurSel _idc]]

<span id='postcolor'>

Share this post


Link to post
Share on other sites

How I can do with "call format"

Call format [" _TempSetAction = "[%1] exec "Gfolder\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)?

Share this post


Link to post
Share on other sites

So, here's my summary/question

A. call executes a string and is functionally identical to ForEach (without _x )

B. Call/ForEach now use local variables, which can be introduced into the scope of the script if private string is used.

C. "" can be used to introduce a string within a string, but for multiple levels we can use {} to indicate strings.

sweet.

and, well, as for who figured out the now-obsolete ForEach trick, I dunno; probably the folks who wrote it. But I didn't learn it from anybody, and have been pretty vocal lately wink.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (uiox @ Oct. 14 2002,12wow.gif)</td></tr><tr><td id="QUOTE">So Bis can't have "feed back" and improve dialogs...

More why implement new features if nobody use dialogs?

I'm happy for slider, but if they had see more missions with dialogs more functions relates to dialogs could be present in 1.85.<span id='postcolor'>

A lotta people don't really understand Dialog Scripting, heck, some can't even get music into their missions. But when you get the hang of it, it gets easier.

I made a nifty "jukebox" dial0g for NPD; It has all the Resistance songs, the original ones and seventh wow.gif :

JukeBox

NOTE: If the link doesn't work (Which it seems not to be on my computer) then use this address:

http://www.freewebs.com/gameer_77/Picture3.jpg

tounge.gif PEACE

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  

×