Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Unit change sides

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Unit change sides Page: [1]
Login
Message << Older Topic   Newer Topic >>
Unit change sides - 9/4/2021 1:00:30 PM   
Gunner98

 

Posts: 5424
Joined: 4/29/2005
From: The Great White North!
Status: offline
I've used this script quite often and at fist blush it works fine:

for i=1,8 do
if ScenEdit_GetUnit({Side='SE Asia Comd', Name="VF-102 Diamondbacks #"..i,}) ~= nil then
ScenEdit_SetUnitSide({Side='SE Asia Comd', Name="VF-102 Diamondbacks #"..i, newside='7th Fleet'})
end
end

Decided to do a quick test and removed one of the units, I thought that the first line of the statement was supposed to look for missing units and if it finds a gap it would just skip over it. Nots so

Removing a unit caused the script to fail. Any thoughts.





Attachment (1)

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Post #: 1
RE: Unit change sides - 9/4/2021 1:50:53 PM   
stilesw


Posts: 1479
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
Hi Bart. This Lua code has worked fine for me in all CMANO/CMO versions recently as this week.

i = 1;
while i < 19 do
if ScenEdit_GetUnit({Side='PRC', Name="J-8F Finback B (Woody) #"..i}) ~= nil then
ScenEdit_SetUnitSide({side="PRC", name="J-8F Finback B (Woody) #"..i, newside="USN"});
end
i = i + 1;
end

-Wayne

(in reply to Gunner98)
Post #: 2
RE: Unit change sides - 9/4/2021 1:52:46 PM   
stilesw


Posts: 1479
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
A little more readable:

i = 1;
while i < 19 do
____if ScenEdit_GetUnit({Side='PRC', Name="J-8F Finback B (Woody) #"..i}) ~= nil then
________ScenEdit_SetUnitSide({side="PRC", name="J-8F Finback B (Woody) #"..i, newside="USN"});
____end
____i = i + 1;
end

(in reply to stilesw)
Post #: 3
RE: Unit change sides - 9/4/2021 8:13:29 PM   
Gunner98

 

Posts: 5424
Joined: 4/29/2005
From: The Great White North!
Status: offline
Thanks Wayne

I'll give it a try. So this cycles through up to 18, then does the same check as the script I was using.

Tx

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to stilesw)
Post #: 4
RE: Unit change sides - 9/4/2021 8:23:16 PM   
stilesw


Posts: 1479
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
The only difference I immediately see is that your code uses the "for...do" construct vs the "while <".
In theory they should both accomplish the same result but do not for some reason. Go figure.

-Wayne

_____________________________

“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)

(in reply to Gunner98)
Post #: 5
RE: Unit change sides - 9/4/2021 9:44:02 PM   
michaelm75au


Posts: 13421
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
I assume you ran 'Tool_EmulateNoConsole(true)' in the console to allow the script to run non-interactive?
Otherwise it will stop on the error to show up the message.

_____________________________

Michael

(in reply to stilesw)
Post #: 6
RE: Unit change sides - 9/5/2021 4:27:57 PM   
Gunner98

 

Posts: 5424
Joined: 4/29/2005
From: The Great White North!
Status: offline
ahhh, no. I didn't do that. Thanks for the tip

B

_____________________________

Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/

(in reply to michaelm75au)
Post #: 7
RE: Unit change sides - 9/5/2021 8:44:51 PM   
KnightHawk75

 

Posts: 1351
Joined: 11/15/2018
Status: online
interactive ...issue

just wrap it in pcall to surpess the interactive error, on error retval will be false.
for i=1,8 do
  local retval,unit = pcall(ScenEdit_GetUnit,{Side='SE Asia Comd', Name="VF-102 Diamondbacks #"..i,}) ;
  if retval and unit ~=nil then 
    ScenEdit_SetUnitSide({Side='SE Asia Comd', Name="VF-102 Diamondbacks #"..i, newside='7th Fleet'});
  end 
end

(in reply to Gunner98)
Post #: 8
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Unit change sides Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.233