Home   Help Search Login Register  

Author Topic: Pass script into dialog  (Read 2324 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
Pass script into dialog
« on: 05 Jun 2008, 05:22:08 »
Hello   : ;)

I am working on an RPG Mission, and have built a dialog for Shops and a menu for the cops to arrest and all that kind of stuff. But am having trouble passing the parameters from the action to the dialog.

Am looking for some help Please!

-DaChevs


here is my dialog:
Code: [Select]
class shop_dialog
{
  idd = -1;
  movingEnable = true;
  controlsBackground[] = {DLG_BACK1, FRAME1};
  objects[] = { };
  controls[] = {LIST2, BUTTON3, BUTTON4};

  class DLG_BACK1: RscText
  {
     colorBackground[] = {0.4, 0.4, 0.4, 0.75};
     text = ;
     x = 0.2125;
     y = 0.02534;
     w = 0.59375;
     h = 0.87329;
  };
 class FRAME1 : RscText
 {
  x = 0.2125
  y = 0.02534
  idc = -1
  w = 0.59375
  h = 0.87329
  style = ST_FRAME
  colorText[] = {1, 1, 1, 1};
  colorBackground[] = {0.4, 0.4, 0.4, 0.75};
  SizeEX = 0.025
 text = "Vehicle Shop"
  };
 class LIST2 : RscListBox
 {
  x = 0.28375
  y = 0.09357
  idc = 105
  w = 0.41125
  h = 0.63938
  style = ST_LEFT
  colorText[] = {0.2, 0.2, 0.2, 1};
  colorBackground[] = {0.4, 0.4, 0.4, 1};
 font = "TahomaB"
  SizeEX = 0.025
  colorSelect[] = {0.4, 0.4, 0.4, 1};
  colorSelectBackGround[] = {0.2, 0.2, 0.2, 1};
  soundSelect[] = {"", 0.1, 1};
  RowHeight = 0.04
  };
 class BUTTON3 : RscButton
 {
  x = 0.30625
  y = 0.78168
  idc = -1
  w = 0.143
  h = 0.04
  style = ST_CENTER
  colorText[] = {0, 0, 0, 1};
        colorActive[] = {0, 0, 0, 0};
colorDisabled[] = {0, 0, 0, 0.1};
colorBackground[] = {0,0,0,0.3};
colorBackgroundActive[] = {0,0,0,0.4};
colorBackgroundDisabled[] = {0,0,0,0.3};
colorFocused[] = {0.84,1,0.55,1};
colorShadow[] = {1, 1, 1, 0.1};
colorBorder[] = {0, 0, 0, 0.1};
offsetX = 0;
offsetY = 0;
offsetPressedX = 0;
offsetPressedY = 0;
borderSize = 0;

soundEnter[] = {"", 0.15, 1};
 font = "TahomaB"
  SizeEX = 0.025
 text = "PURCHASE"
 action = "[lbCurSel 1, ""car""] execVM ""DCV_Scripts\buy_vehicles.sqf""; closeDialog 0";
 default = false
  };
 class BUTTON4 : RscButton
 {
  x = 0.54625
  y = 0.78168
  idc = -1  x
  w = 0.14
  h = 0.04003
  style = ST_CENTER
  colorText[] = {0, 0, 0, 1};
        colorActive[] = {0, 0, 0, 0};
colorDisabled[] = {0, 0, 0, 0.1};
colorBackground[] = {0,0,0,0.3};
colorBackgroundActive[] = {0,0,0,0.4};
colorBackgroundDisabled[] = {0,0,0,0.3};
colorFocused[] = {0.84,1,0.55,1};
colorShadow[] = {1, 1, 1, 0.1};
colorBorder[] = {0, 0, 0, 0.1};
offsetX = 0;
offsetY = 0;
offsetPressedX = 0;
offsetPressedY = 0;
borderSize = 0;

soundEnter[] = {"", 0.15, 1};
 font = "TahomaB"
  SizeEX = 0.025
 text = "CLOSE"
 action = "closeDialog 0;"
 default = false
  };
};

I tried what Mandoble told me to do. But I still couldn't get it to make the car. Please Help  :(


"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Pass script into dialog
« Reply #1 on: 05 Jun 2008, 05:32:08 »
The IDC of your listbox isn't 1, but 105. :) Hence : lbcursel 105, not 1.

After that, _this select 0 will be whatever cursel is (it'll be -1 if it's not selected at all, 0 if it's the first element in the listbox, 1 if it's the second etc.). So for instance if you've first added two elements to the listbox :

Code: [Select]
lbAdd [105, "Thing 1"];
lbAdd [105, "Thing 2"];

Then when you click the button and have "thing 2" select, then _this select 0 will be 1 :)

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #2 on: 05 Jun 2008, 05:40:32 »
ok so in my script that I have activate.

first I switch the cursel to 105.

then in my script that activates on the button I put:

_item = _this select 0;

_item createvehicle (getPos player);

so if I have Thing 1 selected, Thing 1 will be created?

sorry I am really new with dialogs.

here my script to create the dialog:
Code: [Select]
_ok = createDialog "shop_dialog";

_index = lbAdd [105, "[ $2,000 ] Skoda"];
lbSetData [105, _index, "Skoda"];
_index = lbAdd [105, "[ $2,000 ] Skoda (Blue)"];
lbSetData [105, _index, "SkodaBlue"];
_index = lbAdd [105, "[ $2,000 ] Skoda (Green)"];
lbSetData [105, _index, "SkodaGreen"];
_index = lbAdd [105, "[ $2,000 ] Skoda (Red)"];
lbSetData [105, _index, "SkodaRed"];
_index = lbAdd [105, "[ $3,500 ] Sedan"];
lbSetData [105, _index, "car_sedan"];
_index = lbAdd [105, "[ $4,500 ] Landrover"];
lbSetData [105, _index, "Landrover"];
lbSetCurSel [105, 0];

_menu = _this select 0;
_selection = _this select 1;
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Pass script into dialog
« Reply #3 on: 05 Jun 2008, 23:05:13 »
Well, it's not quite that easy.

What you need in your filler-buyer script there is a way to find out whether the button has been pressed or not, and if it's pressed, what to do. The easiest thing is to keep the two scripts separate: have one script that runs when the dialog is created, which adds all the listboxes etc., and then simply exits. Then have a second script which is run from the button-press (as you're showing) which then starts from the beginning.

Afterwards, you just need to -retrieve- the data from the listbox as well (which you've added with lbsetdata). So your button-script might look like this:

Code: [Select]
_index = _this select 0;
_whatever= _this select 1;

_cartype = lbData [105, _index];
_newcar = _cartype createvehicle getpos Player;

Now, your problem is you still need to deduct the price of the car from the player! No worries though,you can also add ARRAYS to the lbSetData command, by using a little trick:

Simply turn your array into a string before adding it with the lbsetdata command:

Code: [Select]
lbsetData [105, str(["Skoda", 2000])]
And then when you load it, simply UNstring it using call compile:

Code: [Select]
_cararray = call compile (lbData [105, _index)];
_cartype = _cararray select 0;
_carcost = _cararray select 1;

Note, I might be mistaken about the exact syntax of the call compile, but if you want to see it in action just poke around my RUG Inventory script and you'll see I stringify everything in the Filler script and then unstringify it in the actual action scripts.

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #4 on: 09 Jun 2008, 21:51:34 »
thanks for help. But I back where I start. Can't get car to make  :dunno:

heres the one to open the dialog:

Code: [Select]
_ok = createDialog "shop_dialog";

lbAdd [105, "[ $2,000 ] Skoda"];
lbsetData [105, str(["Skoda", 2000])];

lbAdd [105, "[ $2,000 ] Skoda (Blue)"];
lbsetData [105, str(["SkodaBlue", 2000])];

lbAdd [105, "[ $2,000 ] Skoda (Green)"];
lbsetData [105, str(["SkodaGreen", 2000])];

lbAdd [105, "[ $2,000 ] Skoda (Red)"];
lbsetData [105, str(["SkodaRed", 2000])];

lbAdd [105, "[ $3,500 ] Sedan"];
lbsetData [105, str(["car_sedan", 3500])];

lbAdd [105, "[ $4,500 ] Landrover"];
lbsetData [105, str(["Landrover", 4500])];

lbSetCurSel [105, 0];




then I have this as action in dialog:
Code: [Select]
action = "[lbCurSel 105, ""car""] execVM ""DCV_Scripts\buy_vehicle.sqf""; closeDialog 0";


this my buy_vehicle.sqf
Code: [Select]
_index = lbCurSel 105;
_whatever= _this select 1;
_cararray = call compile (lbData [105, _index]);
_cartype = _cararray select 0;
_carcost = _cararray select 1;

_veh = _cartype createvehicle (getpos Player);

no errors, but no car... :(
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Pass script into dialog
« Reply #5 on: 10 Jun 2008, 06:30:42 »
You need to put "closedialog 0" at the end of the buy script - otherwise stuff such as "lbcursel" and "lbdata" will be lost as the dialog closes! Also run a hint (hint format ["%1", _cararray]) to make sure the cararray is being "returned" properly by the call compile.

Wolfrug out.



"When 900 years YOU reach, look as good you will not!"

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #6 on: 10 Jun 2008, 20:54:46 »
Ok thanks. First off I want to say thanks Wolfrug for helping me so much and so quickly.

now I put two hint formats in. One where it opens the dialog, and the other in the buy_vehicle.sqf

The first hint says the Scalarboolarray0xeeefff thing.

The second says <null>  :dunno:

"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #7 on: 16 Jun 2008, 01:46:48 »
PLEASE HELP. I have no more help for 3 days now, and this is the biggest thing I need for my mission.

PLEASE  :dunno:
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: Pass script into dialog
« Reply #8 on: 16 Jun 2008, 03:46:24 »
can you post the code for the hints?

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #9 on: 16 Jun 2008, 04:39:47 »
hint format ["%1", _cararray];
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Pass script into dialog
« Reply #10 on: 16 Jun 2008, 05:37:24 »
DaChevs: Did you do what I told you? :) Meaning moving the "closedialog" command from the button to the end of the buyvehicle script? Also, where did you place the hint format? -after- you actually define _cararray, right? There is no point in placing a hint format in the opening script, since there is no local variable named _cararray.

So, in other words.

Code: [Select]
action = "[lbCurSel 105, ""car""] execVM ""DCV_Scripts\buy_vehicle.sqf"""
And

Code: [Select]
_index = lbCurSel 105;
_whatever= _this select 1;
_cararray = call compile (lbData [105, _index]);
_cartype = _cararray select 0;
_carcost = _cararray select 1;

_veh = _cartype createvehicle (getpos Player);
hint format ["Car array:%1, Index number: %2", _cararray, _index];

Now run that instead (changing the action and the script) and then tell us what the hint returns. :) Sorry for the slow delay.

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline ModestNovice

  • Members
  • *
Re: Pass script into dialog
« Reply #11 on: 16 Jun 2008, 21:25:42 »
No problem Wolfrug, sorry for getting jumpy.

Yeah I changed the action and all, but I will work with what you said and see if I get to work.

Thanks Wolfrug.

EDIT:

Okay I get Car array: Scalar Bool Array Oxeefff  Index Number: 0
« Last Edit: 17 Jun 2008, 18:09:51 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley