Jump to content

Photo
- - - - -

Converting string value to object name!


  • Please log in to reply
12 replies to this topic
Thread Starter
The_Captain
The_Captain

    Gunnery Sergeant

  • Members
  • 427 posts

Posted 14 October 2002 - 03:57 #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.

vektorboson
vektorboson

    Supreme OFP Nerd

  • Members
  • 1265 posts

Posted 14 October 2002 - 09:04 #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 [_idc, _sel]
_com = format ["tmp = %1", _obj]
_com foreach [0]

_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.

GAMEER_77
GAMEER_77

    Gunnery Sergeant

  • Members
  • 436 posts

Posted 14 October 2002 - 09:17 #3

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

Posted Image

Posted Image PEACE
NPD2
NPD Forums

whisperFFW06
whisperFFW06

    Gunnery Sergeant

  • Members
  • 505 posts

Posted 14 October 2002 - 09:21 #4

Did not know this trick was possible, it's awesome!!!
Who's puzzled brain has created this? Posted Image :
"Well, I need a command which execute Strings. Foreach do execute a string. So let's use Foreach [0]......"

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

GAMEER_77
GAMEER_77

    Gunnery Sergeant

  • Members
  • 436 posts

Posted 14 October 2002 - 09:25 #5

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

Posted Image PEACE
NPD2
NPD Forums

Suma
Suma

    BI Developer

  • 3707 posts

Posted 14 October 2002 - 09:52 #6

Posted Image4--></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bigpoppa @ Oct. 14 2002,11Posted Image4)</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
[/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 [_idc, _sel]
private "_tmp"
_com = format ["_tmp = %1", _obj]
_com foreach [0]
_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 [_idc, _sel]
private "_tmp"
call format ["_tmp = %1", _obj]
_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 "_yourObject"
call format ["_yourObject = %1", lbData [_idc, lbCurSel _idc]]
[/QUOTE]<span id='postcolor'>




Ondrej Spanel, BIS Lead Programmer

GAMEER_77
GAMEER_77

    Gunnery Sergeant

  • Members
  • 436 posts

Posted 14 October 2002 - 09:56 #7

Is this a glimpse at to what 1.85 has to offer? Posted Image Nice...

Posted Image PEACE
NPD2
NPD Forums

uiox
uiox

    Sergeant

  • Members
  • 125 posts

Posted 14 October 2002 - 11:04 #8

Thanks !





vektorboson
vektorboson

    Supreme OFP Nerd

  • Members
  • 1265 posts

Posted 14 October 2002 - 11:36 #9

Thanks for the hints Suma! The Call.command was something I was waiting for! Posted Image

uiox
uiox

    Sergeant

  • Members
  • 125 posts

Posted 14 October 2002 - 12:07 #10

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)?

Dinger
Dinger

    Gunnery Sergeant

  • Members
  • 523 posts

Posted 14 October 2002 - 14:06 #11

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 Posted Image

GAMEER_77
GAMEER_77

    Gunnery Sergeant

  • Members
  • 436 posts

Posted 14 October 2002 - 14:29 #12

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (uiox @ Oct. 14 2002,12Posted Image)</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.[/QUOTE]<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 Posted Image :

JukeBox

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

http://www.freewebs....77/Picture3.jpg

Posted Image PEACE




NPD2
NPD Forums

Thread Starter
The_Captain
The_Captain

    Gunnery Sergeant

  • Members
  • 427 posts

Posted 16 October 2002 - 05:11 #13

Thanks suma! Didn't think anyone replied to this.
AI Grenadier Aiming Fix
Close Assault: Company level team vs. team game mode for 32 players.