Nicolas Eymerich 0 Posted June 15, 2006 What does happen to local variables? This is the problem: I've a script which allow user to choose what type of units will be created. ;---part of the script--- _Type = _this select 3 (<- arguments passed by another script) ? (_type == "Tank") : goto "Tank" ? (_type == "AA") : goto "AA" Now:the part of the script related to Tank is equal to the part of the script related to AA. However, there're two lines I'd like you to bring your attention: #Tank _object = "Type of tank" createvehicle ... "Type of soldier" createvehicle [Position, group P_red] (<- P_red is the name of a dead man in the editor) "Type of soldier" createvehicle [Position, group P_red] "Type of soldier" createvehicle [Position, group P_red] _Commander = units (group P_red) select 1 _driver = units (group P_red) select 2 _Gunner = units (group P_red) select 3 [_commander] join GrpNull; [_driver, _gunner] join group _commander ;put in the vehicle the created units _commander moveincommander _object _driver moveindriver _object _gunner moveindriver _object. The part above of the script is equal to "AA" Okay, now the fun () thing. I launch twice times the script (distance ~2 second one form each other). In the first time, the script creates the AA and it is all right. The second time, the script should create the Tank. And it does that but... the crew is not inside the tank... Yesterday evening, pretty tired, I've tried to change those lines (only in the tank part) _Commander = units (group P_red) select 4 _driver = units (group P_red) select 5 _Gunner = units (group P_red) select 6 insted than _Commander = units (group P_red) select 1 _driver = units (group P_red) select 2 _Gunner = units (group P_red) select 3 And it worked.... Why??? and, of course, how Can I solve this problem and where do am I mistaken? Share this post Link to post Share on other sites
Trapper 0 Posted June 15, 2006 _Commander = units (group P_red) select 1 Any group is always global. Group P_red unit array on first execution: [commander, driver, gunner] On second execution: [commander, driver, gunner, 2commander, 2driver, 2gunner] Your first try moved the first crew into the second AA tank. This select 3 / 4 / 5 will only help once because of the right but still static selection. Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted June 15, 2006 Thanks for your reply Trapper But I didn't get it.... Sorry, Could you explain in a different way, please? Share this post Link to post Share on other sites
Trapper 0 Posted June 15, 2006 Let's see... A group is always global. units (group P_red) returns an array of all units in group. So P_red acts like a global array variable. Group count P_red at first is 1, after a few seconds it's 0 because the death of the only member is recognized. At first script execution group count becomes three. At the 2nd six, at the 3rd nine and at the 4th twelve. A group can't be bigger than twelve. The remaining local parts of every script execution always select the first three units in the group array (global). So always the first spawnend soldiers are moved between vehicles and the later ones are ignored. Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted June 16, 2006 Thank you very much (again) for your interesting consideration... Quote[/b] ]At first script execution group count becomes three. At the 2nd six, at the 3rd nine and at the 4th twelve However there's something I don't understand (please have patience)... I mean: if "units group P_red" act as a(global) array and if I use the fllowing statement: [_commander] join grpnull; [_driver, _gunner] join group _commander The array "units group P_red" should return 0 (the original dead man because the squad is now composed by a single dead man) the first time I launch the script. And so should happen even he second time and the third time and so on... However, your considerations explain very well the reasons the script does'nt work... So what is the mistaken I'm still doing? And How can I bypass it? Share this post Link to post Share on other sites
Trapper 0 Posted June 16, 2006 Hm, that's my fault. You're right grpNull should do it. I've overlooked the grpNull line. - Hopefully my false theory still helps to find a solution. It looks like the group changes are faulty. I don't know if this is exactly your script as I notice some possible syntax errors: "Type of soldier" <s>createvehicle</s> createunit [Position, group P_red] _Commander = <s>units (group P_red) select 1</s> units P_red select 1 [_commander] join GrpNull; [_driver, _gunner] join <s>group</s> _commander (comref is self-contradictory about that) Try to check script lines in question with hints like this: hint format ["Group is %1",p_red] Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted June 19, 2006 Quote[/b] ]Hm, that's my fault. You're right grpNull should do it. I've overlooked the grpNull line. - Hopefully my false theory still helps to find a solution. It looks like the group changes are faulty. It's all right Don't worry... I've compiled a new script and I've understand that the real problem wasn't in the script I've posted but in another one... Thanks however for your help By the way: I'm searching a 3d dialog tutorial (I've already the utility writtwen by VektorBoson). Do you know if is there anyone on the web or do you know someone who can help me? Share this post Link to post Share on other sites