Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

LUA Question.

 
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 >> LUA Question. Page: [1]
Login
Message << Older Topic   Newer Topic >>
LUA Question. - 9/23/2019 6:42:24 PM   
tjhkkr


Posts: 2400
Joined: 6/3/2010
Status: offline
I am not seeing what I am doing incorrectly. The LUA script does not throw me any diagnostics. But it also does not turn on the radars.
I do see the I have EMCON all caps, but the main LUA page shows that.
Neither works
====
math.random(os.time())
a = 0
b = 3
string.WorkUnit = {'Radar Alfa', 'Radar Bravo', 'Radar Charlie'}

repeat
a = a + 1
r = math.random(1,5)
if r < 3 then
ScenEdit_SetEMCON('Mission', string.WorkUnit[a], 'Radar=Active')
else
ScenEdit_SetEMCON('Mission', string.WorkUnit[a], 'Radar=Passive')
end
until a >= b
====
math.random(os.time())
a = 0
b = 4
string.WorkUnit = {'Vehicles Alfa', 'Vehicles Bravo', 'Vehicles Charlie', 'Radar Surface Alfa'}

repeat
a = a + 1
r = math.random(1,5)
if r < 3 then
ScenEdit_SetEMCON('Unit', string.WorkUnit[a], 'Radar=Active')
else
ScenEdit_SetEMCON('Unit', string.WorkUnit[a], 'Radar=Passive')
end
until a >= b
====
Does the EMCON for the unit and or mission have to be set a certain way for this to work?

Again no diagnostics but does not work. I printed the random number as well as the work unit... it all looks good.

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
Post #: 1
RE: LUA Question. - 9/23/2019 9:41:21 PM   
Whicker

 

Posts: 644
Joined: 6/20/2018
Status: offline
are you moving time forward? it won't happen without time advancing a second or two.

(in reply to tjhkkr)
Post #: 2
RE: LUA Question. - 9/24/2019 12:21:50 AM   
tjhkkr


Posts: 2400
Joined: 6/3/2010
Status: offline
Yes, I did, several times to make sure I was not losing it.
The radar never came on.
Does the unit itself need a special setting?

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to Whicker)
Post #: 3
RE: LUA Question. - 9/24/2019 2:28:27 AM   
KnightHawk75

 

Posts: 197
Joined: 11/15/2018
Status: offline
Doesn't look like ScenEdit_SetEMCON problem, looks like logic issue.

Not entirely clear what you're trying to do from the code above.
Is it something like 40% chance of changing the emcom on all table entries, or is it pick a single random unit and have 40% active\60% passive change on that one only?

Attached text file (to maintain formatting) should provide both examples or help if it's some variation, slap it into the console, change the unitnames and try it.

Also note the line math.random(os.time) in your post is wrong, I think you meant math.randomseed(os.time) there, though you may not need any calls to randomseed at all (at least while working in console).

Hope this helps.

Edit:
btw not that it matters much, but the debug lines:
print('Invalid parameters, nil, or table with less than two entries.');
Should read:
print('Invalid parameters, table nil, or table with no rows');


Attachment (1)

< Message edited by KnightHawk75 -- 9/24/2019 2:48:51 AM >

(in reply to tjhkkr)
Post #: 4
RE: LUA Question. - 9/24/2019 2:46:42 AM   
Whicker

 

Posts: 644
Joined: 6/20/2018
Status: offline
Do you have the radar set to obey parent or whatever that top checkbox is? I think it needs to be checked? I do usually have trouble trying to do this, it always works in the end but the inheritance seems to give me trouble.

(in reply to KnightHawk75)
Post #: 5
RE: LUA Question. - 9/24/2019 2:52:52 AM   
KnightHawk75

 

Posts: 197
Joined: 11/15/2018
Status: offline
quote:

ORIGINAL: Whicker

Do you have the radar set to obey parent or whatever that top checkbox is? I think it needs to be checked? I do usually have trouble trying to do this, it always works in the end but the inheritance seems to give me trouble.


Whicker,
Since he's not specifying 'Inherit' in the call parameters, it will auto disable inheritance by default even if already set, least this has been my experience in testing.


< Message edited by KnightHawk75 -- 9/24/2019 3:29:38 AM >

(in reply to Whicker)
Post #: 6
RE: LUA Question. - 9/24/2019 3:33:11 AM   
KnightHawk75

 

Posts: 197
Joined: 11/15/2018
Status: offline
That said in general you do have to be careful when doing missions,groups,etc to make sure your also not un-enabling the inheritance if ALSO screwing with units assigned to same mission\groups...unless such specifics are wanted. It's all a matter of what the person actually wants and the 'starting point' or assumed 'starting point' so to speak. :)

ie... assume the following sort of default
Mission1 - [inherited]
-Unit1 [inherited]
-Unit2 [inherited]
-Unit3 [inherited]

Mission2 - [inherited]
-Unit4 [inherited]
-Unit5 [no parent]

Mission3 - [no parent]
-Unit6 [no parent]
-Unit7 [no parent]

ScenEdit_SetEMCON('Mission', Mission1, 'Inherit;Radar=Active')
Will effectively set Mission1 to Active emcom along with Active on anything assigned to the mission whom already have inherited set. _However_ since it's STILL inheriting, it may get overridden from above.

ScenEdit_SetEMCON('Mission', Mission1, 'Radar=Active')
Will effectively set Mission1 to Active emcom along with active on anything assigned to mission one who already have inherited set. Mission1 should not get overridden from above it WILL be Active, As will be Units 1-3.

Then say you ran ...
ScenEdit_SetEMCON('Unit', Unit2, 'Inherit;Radar=Passive') --Would effectively do nothing.
ScenEdit_SetEMCON('Unit', Unit2, 'Radar=Passive') --Would make the change and flag Unit to as not using parent.


More..
ScenEdit_SetEMCON('Mission', Mission2, 'Radar=Active')
Will effectively set Mission2 to Active emcom along with active on anything assigned to mission2 who already have inherited set. Unit4 will be Active, Unit5 WILL NOT get set Active, till specifically told to inherit, or changed specifically.

Then say...
ScenEdit_SetEMCON('Unit', Unit5, 'Inherit') Would set Unit5 to Inherit and it would take the Active setting for Mission2 just set above.

ScenEdit_SetEMCON('Mission', Mission3, 'Radar=Passive')
Will set the mission3 Passive but not change jack on unit6 or unit7...till they are marked to inherit in code, or someone manually resets them or presses the reset on all effective units button for mission3.


Yeah it can get involved if you're screwing with units and the mission they belong to at basically the same time.
If you want to ensure things are sticky when setting it on Mission or Groups, I recommend looping though all members of said mission\group and applying an "inherit;" flag. That way you know whatever specific units were members are forced to take the change. That is ...unless you're doing something cool like trying to get a flight of say 4 f-35's to have 1 guy be the cec-radar and the others missile trucks,etc. But I digress. :)


< Message edited by KnightHawk75 -- 9/24/2019 3:38:30 AM >

(in reply to KnightHawk75)
Post #: 7
RE: LUA Question. - 9/24/2019 10:13:43 PM   
tjhkkr


Posts: 2400
Joined: 6/3/2010
Status: offline
quote:

ORIGINAL: KnightHawk75
Doesn't look like ScenEdit_SetEMCON problem, looks like logic issue.

Not entirely clear what you're trying to do from the code above.
Is it something like 40% chance of changing the emcom on all table entries, or is it pick a single random unit and have 40% active\60% passive change on that one only?

Attached text file (to maintain formatting) should provide both examples or help if it's some variation, slap it into the console, change the unitnames and try it.

Also note the line math.random(os.time) in your post is wrong, I think you meant math.randomseed(os.time) there, though you may not need any calls to randomseed at all (at least while working in console).

Hope this helps.

Edit:
btw not that it matters much, but the debug lines:
print('Invalid parameters, nil, or table with less than two entries.');
Should read:
print('Invalid parameters, table nil, or table with no rows');


I think you meant math.randomseed(os.time) there
Thank you; I did not know that...
Or maybe I did and I am mixing BASIC with LUA

Rather than have a dozen triggers/events, I put all the sensors in the table:
string.WorkUnit = {'Vehicles Alfa', 'Vehicles Bravo', 'Vehicles Charlie', 'Radar Surface Alfa'}
And then using an incrementing variable, walk each one through the code. It advances correctly when I have run the diagnostics.
It simply does not turn on the lights when it reaches the 40% threshold... and yes, it is triggered every 5 minutes with a 60% chance of being off and a 40% chance of being on. I would like to test every three minutes, but one problem at a time.

So the consensus is: check the inherit box.


_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to KnightHawk75)
Post #: 8
RE: LUA Question. - 9/25/2019 2:29:01 PM   
KnightHawk75

 

Posts: 197
Joined: 11/15/2018
Status: offline
uh, that wasn't my consensus per say tjhkkr.

The inheritance examples was specific to settings on 'mission' or 'group' emcom settings and understanding the effects vs desired or assumed effects, ie need know what your changing and what you are not under different circumstances, which can lead to unexpected results if not careful.

As for what you want I think I captured it all in the attached example scenario.
It flips a bunch of units radars and oecm on off every 3 minutes by default no matter wtf inheritance they already have or don't have from above, 40% chance of on every cycle, 60% off chance every cycle. Works perfectly for me. Run it for a minute or two on 5x time on side red you'll see it working.

Copy and paste as need for you own scenario from the two triggers & action scripts (one on-startup, one every minute).


TimedRadarFlipper.zip


Attachment (1)

(in reply to tjhkkr)
Post #: 9
RE: LUA Question. - 9/26/2019 7:45:19 PM   
tjhkkr


Posts: 2400
Joined: 6/3/2010
Status: offline
quote:

ORIGINAL: KnightHawk75
uh, that wasn't my consensus per say tjhkkr.
The inheritance examples was specific to settings on 'mission' or 'group' emcom settings and understanding the effects vs desired or assumed effects, ie need know what your changing and what you are not under different circumstances, which can lead to unexpected results if not careful.
As for what you want I think I captured it all in the attached example scenario.
It flips a bunch of units radars and oecm on off every 3 minutes by default no matter wtf inheritance they already have or don't have from above, 40% chance of on every cycle, 60% off chance every cycle. Works perfectly for me. Run it for a minute or two on 5x time on side red you'll see it working.
Copy and paste as need for you own scenario from the two triggers & action scripts (one on-startup, one every minute).
TimedRadarFlipper.zip

Thank you Knighthawk! Appreciate it.


_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to KnightHawk75)
Post #: 10
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> LUA Question. 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.131