Home   Help Search Login Register  

Author Topic: using edit field to set direction and distance to create a marker.  (Read 3124 times)

0 Members and 1 Guest are viewing this topic.

Offline jones

  • Members
  • *
You have to bear with me as I am new to scripting. My intent is to use edit fields in a dialog to set a position on the map to create a marker using distance and direction.
I plan on using this for a foward obsever / fire control script with artillery or missiles. I have spent some time know getting a handle on dialogs and I have done a few smaller scripts. Nothing fancy. I have the frame work for what I want but i am still inexperienced with scripting.
How I inted this script to work. There will be a foward observer and he can bring up his postion in relation to a register fire gun. (Center formation) in distance and degrees, i.e 327 degrees at 1200 meters. I have completed this part of the script. The fire control officer will then have a simple UI and will have to calculate the fire mission and enter it into the dialog and mark target and or call fire mission. The FO tells the FCO his position from the register fire gun and the distance and direction of the target from is position . The FCO will have to use a little math to determine the direction and distance of the the target. And or have predesignated targets areas to effectively hit the target. I would just like to create a system that has a higher learning curve than clicking on the map.

I have created a dialog, albiet a simple one that has two text fields, two edit fields, two active text fields, and two buttons.
the edit fields are for distance and direction, the two active text fields are to set the text from the edit box to confirm the distance and direction. And one button to close the dialog and one to create the marker. The dialog is fully functional now this is where things get rough for me. I need to be able to take the numerical distance and direction values and use them to create the marker on the map which I will later use to call a fire mission with an artillery or missile script. The first hump is just being able to create the marker. If i can get to that point i should be able to run with it. Now as i understand the forEach command can be used to do this but i am still a bit stumped, over my head. But that is generally how I learn. By biting off more than I can chew.

As I am new to scripting and there doesn't seem to be much comprehensive writing on scripting and what I do find is a bit discobobulated. If anyone can point me to some good referance material that would help me with this task and maybe provide a bit of guidance. It would be much appreciated. I am not asking for anyone to do it for me, I am doing this essentially to learn scripting.
thanks for your time
Jones

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
So your problem with the dialog is to get the numerial values from the edit fields?

Offline jones

  • Members
  • *
Yes. If I execute the script from the dialog can I use the number values to set the position based on distance and direction. for example, I take the direction value of say 180 degrees from the edit field and use it with the setdir command. i have looked around and haven't found anything to set distance from point A to point B. But I am sure there is something around. still looking.

i am thinking you could get the units position set the direction with the number value from the direction edit field plus the distance from the value of the distance edit field.
« Last Edit: 16 Aug 2007, 03:34:04 by jones »

Offline Nixer6

  • Members
  • *
As I am new to scripting and there doesn't seem to be much comprehensive writing on scripting

Thank you sir. I brought this up on this forum, re: a Scripting school, months ago. Nobody seemed to think it was needed.

There is lots of info out there, especially on the posts in this forum. I am not knowledgeable enough to combine it all into a big tutorial. I sure wish someone would do an .SQF for Dummies tutorial.  :yes:

I'd be the first avid reader of it. If you are making dialogs, you are way ahead of me.  :D
Why do I have to be a Rocket Scientist to make a good mission?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Once you retrieve the text of an edit control with ctrlText, you may convert it to number using parseNumber.

And welcome to the scripting world  :clap:

Offline jones

  • Members
  • *
I made a dialog with a button and an edit field. and then made a script called hint.sqs the button executed the script and the first test I did looked like this.
_dir =ctrltext F_DIR     // F_DIR is the name of the idc of the edit field
hint format ["Direction: %1", _dir]


This just returned the whole string, what ever i put into the edit field. Then I changed the script to this.

_dir =ctrltext F_DIR     // F_DIR is the name of the idc of the edit field
hint format ["Direction: %1", parsenumber_dir]


This in turn returned only a number value, if I put in letters it returned 0

Thanks for the little nuggets of info Mandoble.

Now the next step is to figure out how to take that and set a direction and add distance to the direction in order to set a position to create a marker at.
Is this possible? There is the set direction command but I haven't seen anything regarding setting a distance. Anyone have a little info to steer me in the right direction?
« Last Edit: 17 Aug 2007, 02:26:18 by jones »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
You have a direction and a range relative to who, the observer or the firer?

Offline jones

  • Members
  • *
I want to set the distance and direction from the firer.
So if I put in the direction: 300 distance 1200 it will create the the marker 300 degrees and 1200 meters from the firer.

Offline jones

  • Members
  • *
I am at a loss with this challenge thus far.
« Last Edit: 17 Aug 2007, 07:44:38 by jones »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Just as an example:
Code: [Select]
_angle = 300;
_dist = 1200;
_firer = player;

_marker_pos = [(getPos _firer select 0)+sin(_angle)*_dist, (getPos _firer select 1)+cos(_angle)*_dist];

Offline jones

  • Members
  • *
That is basically what i was trying, some where along the lines I screwed the pooch. But I think i can get it working.

I have spent most of time getting dialogs down as they seem fairly straight foward and now I am focusing on the actual scripting.
It seems it would be better to assign the values and the intitial arguments of a dialog in a seperate script so that they can be used with multiple scripts. Basically so all the data going to and from the dialog is handled seperately. Also i would like things in neat little boxes so it makes more sense to me later and to someone else that is reading it.
So I write the dialog seperatly and include it in the descritpion.ext then I write all the arguments for the dialog in another script so that i can use them in multiple places. then the last script that actually effects the game just uses the variables from script that has the arguments for the dialog.

in this order;

Description.ext
dialog
dialog argument script
script to execute

If I set the argument up initially that,

_angle = parsenumber ctrlText F_DIR
_dist = parsenumber ctrlText F_DIS

Then I will not have to state that argument again if I want to use it in multiple places.

My question is how do I link the dialog with the script that has the arguments for the dialog?
I know this is probably a no brainer and when someone points it out to me I will probably kick myself.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Best way to link dialogs and controls inside dialogs with scripts is using dialog and controls event handlers

For example:
Code: [Select]
class DlgMyDialog
{
   idd = -1;
   movingEnable = true;
   onLoad = "res = [""onLoad"", _this] execVM ""MyDialogHadler.sqf""";

... rest of dialog definition here
};

Code: [Select]
// MyDialogHadler.sqf

_event = _this select 0;

switch (_type) do
{
   case "onLoad":
   {
   // Dialog is being loaded, put code here to initialize any of its controls
   };

   case "MyWonderfulButton1Clicked":
   {
   // etc etc etc
   };

   default
   {
   };
};

Offline jones

  • Members
  • *
mandoble,
Thanks for the info. Some handy stuiff there. I will play around with it until it does my bidding

Offline jones

  • Members
  • *
For some reason I can not get the numerical values to return properly. I did a test with a hint and it worked then when i tried to do it again it just returned "scalar" and it sets my position all the way to the south west. IF i put the numbers in manually in the script itis right on the money where I want it to go. Like this;

_dir = 300
_dis = 1200
_RG = RGun
_pos = [(getPos _RG select 0)+sin(_dir)* _dis, (getPos _RG select 1)+cos( _dir)*_dis]
WTarget setpos _pos

But if I write the code like this and try and return the values using the idc from the edit field I get the "scalar" and the position in in the the south west.

_dir = ctrltext parsenumber F_DIR
_dis = ctrlText parsenumber F_DIS
_RG = RGun
_pos = [(getPos _RG select 0)+sin(_dir)* _dis, (getPos _RG select 1)+cos( _dir)*_dis]
ATarget setpos _pos

What am I doing wrong?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Code: [Select]
_dir = parsenumber (ctrltext  F_DIR)
_dis = parsenumber (ctrlText  F_DIS)

Offline jones

  • Members
  • *
I changed that line of code and tried it a couple other ways and it wouldn't work for nothing. I ended up changing the IDC on the edit field to a numerical name i.e 100, 101,102. and it worked. For some reason when I give the idc a alphabetical name such as F_DIR it will not return the value.
I guess it doesn't really matter as long as it works. I will just give it a really high numerical name such as 5000. Any thoughts on why it won't return the value if it has a specific name like F_DIR?
For now i will use a numerical idc since it works. I have the framework for what I want so now I can add all the fluff and make it pretty. I really appreciate all the help.

Jones

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
LOL, I supposed your F_DIR, etc were gobal vars with numerical values. Dialogs idds and controls idcs MUST be numbers always.

Offline jones

  • Members
  • *
I released that after 30 minutes of wondering what the hell was going on. My first test F_DIR were vars and I rewrote everything to use witht he script and without thinking made my idc F_DIR ect ect. Felt like a knuckle head when I realized what was wrong.