Home   Help Search Login Register  

Author Topic: Problem with unitname  (Read 861 times)

0 Members and 1 Guest are viewing this topic.

Offline Cheetah

  • Former Staff
  • ****
Problem with unitname
« on: 22 Jul 2006, 12:34:47 »
PROBLEM: Adding parameters to a script, made create a new unit, works, but now I can't select the unit with names I gave to the script in the brackets.

DETAILED:
I execute a script with the following code:
Code: [Select]
[patrol1,"patrol1"] exec "test.sqs";
The script is the following:
Code: [Select]
_patrol1 = "Civilian8" createUnit [getpos out_gate,patrolMaster,format["%1 = this",_this select 1], 0.6, "corporal"]
_patrol1 = _this select 0;

_patrol1 setDammage 1;
_patrol1 doMove getpos player;
hint format ["%1:%2",_this select 0,_this select 1];

The script doesn't work. The unit is created, but can't be commanded by me. He doesn't get killed and doesn't get moved to the location of the player (which is named properly, "player").
It does work when I insert a line like this:
Code: [Select]
patrol1 setDammage 1;
But this way it's not using the variables given to the script when it's activated. So my question is, how can I get this to work. Because I can't use a string to do so, that's why I gave two parameters to the script. But it doesn't work when I use the first parameter, which isn't a string. The game doesn't know that it's an object.

Anyone got a solution?
« Last Edit: 22 Jul 2006, 17:55:01 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Problem with unitname
« Reply #1 on: 22 Jul 2006, 13:22:51 »
I presume that the variable  patrol1 has been initialised somewhere before using your line:

[patrol1,"patrol1"] exec "test.sqs";

It might not be working properly because the variable has not been initialised before the call.

If the variable has been initialised beforehand, I'll crawl back into my corner and shut up.

 8)


Planck
I know a little about a lot, and a lot about a little.

Offline Cheetah

  • Former Staff
  • ****
Re: Problem with unitname
« Reply #2 on: 22 Jul 2006, 17:46:42 »
The purpose of patrol1 is to give me the option of using it as the objectname.
Because when I solely use "patrol1", I can't use this input to give the units I just created orders, because it's a string. So the result is that I get an error "Input string, expected object" (or something like this). So to prevent this, I add the input of patrol1.

So that I can use something like:
_unit = (_this select 0);
_unit setDamage 1;
Without getting the string error, because the engine wants a object name, not a string.

Don't think that I have to initialise patrol1 before running the script, because the unit doesn't even exist before that.

EDIT: SOLVED! Had to use "call" to be able to use "_unit1" to control the selected unit.
Code: [Select]
_unit1 = call format ["%1",_this select 0];
« Last Edit: 22 Jul 2006, 18:59:45 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!