Home   Help Search Login Register  

Author Topic: CT_EDIT: parsing text from edit field to object name  (Read 1183 times)

0 Members and 1 Guest are viewing this topic.

Offline jones

  • Members
  • *
Been banging my head on the wall over this. I want to take the text I put in the edit field and use it as an object name in code.

Simplest Example I can think of:

on the map I place 10 cars and name them car1 - car10

I have 1 edit field in my dialog

basically the idea is to make the car I choose "moveto" by typing the name of the car in the edit box and running the code.

is there a way to use  call format and ctrltxt to do this. I tried various things and kept getting the type string, type expected object error.

I ran this through and didn't get the error but the object didn't execute the command.


Code: [Select]
{call format [_car = %1", (ctrltext IDC)]};
_car moveto.....

or

Code: [Select]
_acar = ctrltext IDC;
{call format ["_car = %1", _acar]};

Basically the same thing.

I didn't get any errors but the object doesn't moveto
Anyone have an insight on how to take text from an edit field convert it to an object name to be executed in code?
I have a dozen things I would like to use this for but can't seem to get it to run.

Respectfully
Jones

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: CT_EDIT: parsing text from edit field to object name
« Reply #1 on: 01 Aug 2008, 07:39:55 »
Try

Code: [Select]
_car = format ["%1", ctrltext IDC];
_car moveto.....

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: CT_EDIT: parsing text from edit field to object name
« Reply #2 on: 01 Aug 2008, 07:59:20 »
I believe the general rule for changing strings into whatever they were before (or, in other words, removing the ""'s around anything) is using call+compile. As so:

Code: [Select]
_string = str (car1);
_car1 = call compile _string;
_car1 doMove getpos _yourplace;

Try it out!

Wolfrug out.

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

Offline jones

  • Members
  • *
Re: CT_EDIT: parsing text from edit field to object name
« Reply #3 on: 01 Aug 2008, 11:24:10 »
Wolfrug thanks a bunch,

I ran it like this

Code: [Select]
_Acar1 = ctrltext IDC;
_car1  = call compile _Acar1;

worked like a charm.
I tend to over complicate things, all part of the learning process though.

Respectfully Jones

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: CT_EDIT: parsing text from edit field to object name
« Reply #4 on: 01 Aug 2008, 17:40:40 »
uh...I have some stuff to learn about ArmA scripting...never heard of compile :P