Home   Help Search Login Register  

Author Topic: Dialog to control units  (Read 4021 times)

0 Members and 1 Guest are viewing this topic.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Dialog to control units
« on: 31 May 2003, 13:35:51 »
According to the comref the lbSetData command stores a string, but what I need is it to store an object, or so to speak. When I try to use any command to control the stored unit, it complains it's a string not an object I'm referring to. Here's how I set it up:

Quote
_listunit = lbAdd [13962,(name(units _unit select _u))]
lbSetData [13962,_listunit,units _unit select _u]
I increment _u so it takes all units of the group to the listbox and the visible text is the units name. Here's how I dig it up:
Quote
_u = 0
_max = (lbsize 13963) - 1
#equiploop
_name = lbText[13963,_u]
_unit = lbData[13963,_u]
removeAllWeapons _unit
_u = _u + 1
? (_u <= _max) : goto "equiploop"

lbClear 13963
exit

So is there a way to control the above _unit? Don't worry about the differing id, I use 1 listbox to gather all units within 50 meters of the leader who uses it, and another where to he can drop the ones he wants to be affected...
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #1 on: 01 Jun 2003, 04:29:22 »
To change a string to an object, try:

format ["",+string ]

So inserting that into your script, should look something like this:

Code: [Select]
...
#equiploop
_name = lbText[13963,_u]
_unit = format [""+(lbData[13963,_u])]
removeAllWeapons _unit
_u = _u + 1
...

I dunno... looks a bit dodgey :P

Try it and see if it works...

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #2 on: 01 Jun 2003, 13:51:17 »
You know what... Na a  ...Sigh,

What's the difference between
_unit = format [""+(lbData[13963,_u])]
and
_unit = format ["%1"+(lbData[13963,_u])] ?

Though, neither worked. Still a string. I am totally confident someone has handled units via listboxes before, there aren't that many other choises... But how exactly I don't know.

Here's a preview. You'll have to be clever to figure out what it's ment for  ;D

O and if anyone knows the paths to the icons you see there on the right, the unit type icons, if there are any whole ones, spill it out or I'll club ya  ;D Also the paths to the sidearms are a mystery to me.
Plz  ::)
« Last Edit: 01 Jun 2003, 16:32:58 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #3 on: 02 Jun 2003, 02:19:05 »
Hmm.... just my dodgey syntax most like... try:

_unit = call format [""+(lbData[13963,_u])]

That should work, according to a quick test run I did, but that wasn't using a dialog...

What's the difference between
_unit = format [""+(lbData[13963,_u])]
and
_unit = format ["%1"+(lbData[13963,_u])] ?

Umm... in the second one you're pointing the format command to a variable that doesn't exist? The %1 would normally be replaced by the variable after the comma, however if you look closely at that line you'll notice there's no comma at all ;)

The "" + XXX merely adds XXX into the empty string "".

Anyway, hope it works for you this time ;)

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #4 on: 02 Jun 2003, 15:32:28 »
We're definitely closing in on the prob, no error this time but no results either  :) Now _unit is a scalar bool array thingy, is that undefined? I can get the text of that listboxs current selection (_u), but still the data seems to be under the rock.

Yeah didn't see that comma heh. Didn't know about that command which fills empty space with something, but filling it in this case with that lbdata, which is invisible, isn't quite working. I could ofcourse take the easy way and take the unit from the trigger which inits the dialog, but that wouldn't be so elegant  ;)
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #5 on: 02 Jun 2003, 16:51:55 »
Tested feeding the listbox with data as follows:
Quote
_info = format ["%1:%2 (%3 / %4)",_u+1,(name(units _unit select _u)),(primaryWeapon(units _unit select _u)),(secondaryWeapon(units _unit select _u))]
_uniti = format ["%1",(units _unit select _u)]
_listunit = lbAdd [13962,_info]
lbSetData [13962,_listunit,_uniti]

So now the data is visible and it is a string. Now it shows up as WEST alpha black:1 and such with the command _unit = lbData[13963,_u]. There is no way to feed anything else than a string into a listbox entry, that I am pretty confident of.
It needs to be converted (in the script that processes it) into something usable for object commands as it now produces an error after reading the first word of the string.
How? :D
« Last Edit: 02 Jun 2003, 17:38:45 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #6 on: 04 Jun 2003, 01:36:49 »
Hmm...

I'm afraid not even my snippets file can tell me how to convert an object into a string...

I'm sure it's possible, but I'm afraid I don't know how it's done... (yet! ;)).

Hopefully someone out there knows and can enlighten us...

Offline CrashDome

  • Members
  • *
Re:Dialog to control units
« Reply #7 on: 06 Jun 2003, 08:08:54 »
I've done it....
You are going about it all wrong actually....there are many ways but here is one

Here's what you need to do:
1. save the objects into an array such as: TEMPARRAY=[object1,object2,etc....]
2. place the integer value of its position in the array into the lbsetdata
i.e. if your array was [object1,object2,object3] then you would
lbsetdata[12345,0,"0"]
lbsetdata[12345,1,"1"]
lbsetdata[12345,2,"2"]

3. to retrieve selected unit use the data in a CALL statement
for example if I had highlighted the third object in the list then:
Code: [Select]
SELECTION= lbData [12345,lbCurSel 12345]
call format["RETRIEVEDOBJECT=TEMPARRAY select %1",selection]
what this does then is retrieve the "2" and assign it to variable SELECTION then rewrites a statement as:
RETRIEVEDOBJECT=TEMPARRAY select 2
and then executes it and assigns object3 to variable RETRIEVEDOBJECT


edit: btw... I am pretty sure you cannot convert an object into a string, and then turn the string back into an object. I wouldn't bet my life on it, but I would bet yours ;)
« Last Edit: 06 Jun 2003, 08:12:53 by CrashDome »

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #8 on: 06 Jun 2003, 16:52:17 »
Ok, that works, with the exception of lbData containing a string ofcourse and lbValue would suit this situation better, maybe it's ment for it, as you can't select a string from an array. Call would convert it ofcourse but why bother  ;D

But thanks now it works  ;)

I still would need info on the pics, the .paa's of sidearms and if there are any images of the units u see at the bottom as whole, I can only find parts like you see in the attachement above...

There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline CrashDome

  • Members
  • *
Re:Dialog to control units
« Reply #9 on: 06 Jun 2003, 23:43:31 »
You know... I missed lbSetValue completely. ::)]

You are absolutely right. Use lbSetValue and eliminate redundant code.

Sorry, don't know the paa's :-[

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #10 on: 07 Jun 2003, 22:30:15 »
Here's a hard one. I'm trying to categorize or just sort the weapons and magazines of a unit for the "database" I've constructed for the weapon dialog. Whenever a unit takes weapons from it his current weapons are stored. I'm using rather complex syntax to retreive them and am getting tangled on nesting multiple while...do and if...then...else structures, just to make it fast,flexible and reliable. This is what I've come up reduced to the structure:


while "a <= b" do
{
if () then {while "" do {}} else { if () then {}}
a = a + 1
}


I can't paste the whole thing here, as it has way too many characters for a post heh. There's 4 of those if structures in that while structure.  The question is, is that possible? Nesting so many. And are multiple while conditions possible?

Atm I'm getting an invalid number in expression error, due to either the spacing, the nested structure or the multiple while conditions, but which could it be?
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

vektorboson

  • Guest
Re:Dialog to control units
« Reply #11 on: 08 Jun 2003, 16:25:54 »
@MI_Fred

nested if and while statements are possible in OFP, but:

while the uppermost if or while statement may expand over several lines, nested if's and while's have to remain in one single line. As I see, they all seem to be in one single line. Perhaps you should check, if you end all statements with a semicolon (even those which end with a closing bracket "}".

I've had a similar problem, best is to outsource them into either variables or sqf-files.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #12 on: 08 Jun 2003, 19:11:30 »
Alright, I should be able to do that, but before I try, I think you'd be able to see from the actual code if it is correctly semicoloned  :)

Quote
if ("_x == _weps select _uwc" count MIF_WQprimaries > 0) then
{
_pri = 0;
_prmax = (count MIF_WQprimaries) - 1;
   while "(_pri <= _prmax) && ((_weps select _uwc) != (MIF_WQprimaries select _pri))" do
   {
   _pri = _pri + 1;
   };
_newPrimStock = (MIF_WQprimstock select _pri);
_newPrimStock = _newPrimStock + 1;
MIF_WQprimstock set [(MIF_WQprimstock select _pri),_newPrimStock];
}
else
{
   if ((_weps select _uwc) == (primaryWeapon _curunit)) then
   {
   MIF_WQprimstock = MIF_WQprimstock + [1];
   MIF_WQprimaries = MIF_WQprimaries + [(_weps select _uwc)];
   MIF_WQprimicons = MIF_WQprimicons + [""];
   _newWep = lbAdd [13968,(MIF_WQprimaries select (_weps select _uwc))];
   lbSetData [13968,_newWep,(MIF_WQprimaries select (_weps select _uwc))];
   };
};
That's the spaced out version of one of the if structures inside the topmost while structure. After I make a sqf out of each of the above, I think I can then just put the call to each of them on a separate line followed by a semicolon. Am I right?

And I wanted to know if the while condition I've put in red is possible, as it has 2 conditions. Somewhere I red that 2 aint possible or then that was some fairy whispering into my ear...  ;D
« Last Edit: 08 Jun 2003, 19:16:37 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #13 on: 09 Jun 2003, 02:26:55 »
Yesh, okey, I found out that in an sqs file you must write everything in 1 row. In an sqf you can space it to multiple rows, as follows. And now the errors are gone. Now I've still got this prob with the double while condition, I'd like a sexier approach to it really  :D and to a few other things some answers. Ok *cough* if I may, (again):
Quote
if ("_x == _curWeapon" count _stock > 0) then
{
_pri = 0;
_prmax = (count _stock) - 1;
while "(_pri <= _prmax) && (_curWeapon != (_stock select _pri))" do {_pri = _pri + 1;};
_newPrimStock = (_stockno select _pri);
_newPrimStock = _newPrimStock + 1;
_stockno set [(_stockno select _pri),_newPrimStock];
}
else add new lb entry and so on...look at 3rd q
What that does is if there is a matching weapon in the database, the red while structure will seek it and place the array pointer to it. Is there a better way to define _newPrimStock?

Secondly, it seems not to work. The number is not incremented. The array set command was new to me just a while back so ...

Thirdly, does _stockno = _stockno + [1]; add a new element to an array and set it to 1 automaticly? That is a number I need to add there, that is needed when a new weapon is put into stock.

[EDIT] Ah hell, why bother, I found out both. array set [index,value] pffft. And I had to resize the array to get in a new value. So now I get everything nicely to the stock except magazines.

I can't tell wether a mag is a normal mag or a sidearm mag as I have them in different lb's. It leads to a plethora of problems... any genius for this one? This is where my brain starts to hurt  :-X [/EDIT]
« Last Edit: 11 Jun 2003, 03:39:46 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline benreeper

  • Members
  • *
  • I'm a llama!
Re:Dialog to control units
« Reply #14 on: 16 Jun 2003, 06:04:44 »
What I did was have the label hold an index to a known array of objects.

Ben