Using ChatGPT to create capture script

Take command of air and naval assets from post-WW2 to the near future in tactical and operational scale, complete with historical and hypothetical scenarios and an integrated scenario editor.

Moderator: MOD_Command

Post Reply
merlinark
Posts: 8
Joined: Tue Sep 06, 2022 2:57 am

Using ChatGPT to create capture script

Post by merlinark »

Hello everyone,

I'm trying to create a module to capture an airbase. ChatGPT helped with some of the lua coding for a simple one unit capture as a test of capture.

-- ============== SIDES ==============
ScenEdit_AddSide({name='Blue', awareness='Aware'})
ScenEdit_AddSide({name='Red', awareness='Aware'})


-- Create a visible reference point circle around Puerto Cabezas airport
ScenEdit_AddReferencePoint{
side='Red',
name='CAPTURE_ZONE',
lat=14.0460, -- Puerto Cabezas Airport approximate center
lon=-83.3867,
highlighted=true
}

-- Set as a circular zone with 10 km radius
ScenEdit_SetZone{ <--------------------------------------------------------Line 16
zone='CAPTURE_ZONE',
isactive=true,
arenaradius=10000 -- 10,000 meters
}
-- Add the USMC Mech Inf Platoon (DBID 4594)
ScenEdit_AddUnit{
side='Blue',
type='Facility',
dbid=4594,
name='USMC Mech Inf Platoon',
lat=14.0465,
lon=-83.3855
}
-- Create the event
ScenEdit_AddEvent{
name='Capture Puerto Cabezas',
isActive=true
}

-- Create the trigger: Blue unit inside zone for 1 minute
ScenEdit_AddTrigger{
event='Capture Puerto Cabezas',
type='UnitRemainsInArea',
name='BlueInZone1min',
unitname='USMC Mech Inf Platoon',
side='Blue',
area={'CAPTURE_ZONE'},
time=60 -- 1 minute
}

-- Action: Change Puerto Cabezas airfield to Blue
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='ChangeUnitSide',
name='FlipAirfield',
newside='Blue',
unitname='Puerto Cabezas Airport'
}
-- Add message popup when the airfield is captured
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='Message',
name='AirfieldSecuredMsg',
description='Airfield secured!'
}


Getting this error
ERROR: [string "Console"]:16: Invalid arguments to method call

Line 16 indicated above.

Any suggestions?

Thanks in advance,
merlinark
Posts: 8
Joined: Tue Sep 06, 2022 2:57 am

Re: Using ChatGPT to create capture script

Post by merlinark »

Quick update:
I manually created the Event/Triggers/Actions.
There wasn't an option to flip unit so I pasted in the LUA section on action

-- Action: Change Puerto Cabezas airfield to Blue
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='ChangeUnitSide',
name='FlipAirfield',
newside='Blue',
unitname='Puerto Cabezas Airport'

I ran the scenario, unit arrived in box and 60 seconds later the Airfield Secured! message appeared.
The airfield was still green and wasn't able to access Aircraft Operations.

Some progress, missing something on the changing sides.
Nikel
Posts: 2328
Joined: Tue Mar 24, 2009 10:51 am

Re: Using ChatGPT to create capture script

Post by Nikel »

I do not know lua code, but I know the AI is very imaginative, inventing functions and stuff.

Not sure it will be useful, but in a scenario designed by Transient, there is an event to capture a Chinese Ro-Ro vessel, the scenario is Operation Ardent Shield (included in the CSP).

This is the line for the event:
ScenEdit_SetUnitSide({side='China', guid='LK465H-0HN7TERUINFMT', newside='Singapore'})
User avatar
SunlitZelkova
Posts: 405
Joined: Tue Mar 06, 2018 11:49 pm
Location: Portland, USA

Re: Using ChatGPT to create capture script

Post by SunlitZelkova »

The AI is indeed making up functions that don't exist. There is no "ScenEdit_SetZone."

Check out this thread for the challenges of using AI to write Lua scripts- https://forums.matrixgames.com/viewtopic.php?t=413668
"One must not consider the individual objects without the whole."- Generalleutnant Gerhard von Scharnhorst, Royal Prussian Army
thewood1
Posts: 10176
Joined: Sun Nov 27, 2005 6:24 pm
Location: Boston

Re: Using ChatGPT to create capture script

Post by thewood1 »

I'll state the obvious...generative AI can be a great productivity tool for experienced coders. But note I said experienced coders. People who are novices in any type of coding will most likely not get good coding outcomes from ChatGPT or other tools. You can engage in a basic conversation to have gAI fetch information and frame in an understandable format. But to generate useful code, you have to already know how to ask the question, know what kind of answer you'll need, and be able to sniff out AI slop.
merlinark
Posts: 8
Joined: Tue Sep 06, 2022 2:57 am

Re: Using ChatGPT to create capture script

Post by merlinark »

Yeah, I started noticing that.
AI got me in the ballpark of what I needed.

I'll give the new code line a try.

Thanks guys,
merlinark
Posts: 8
Joined: Tue Sep 06, 2022 2:57 am

Re: Using ChatGPT to create capture script

Post by merlinark »

Got it working.

Used this command in lua console to get ID:
print( ScenEdit_GetUnit({ name='Puerto Cabezas Airport' }).guid )
MTJZF8-0HNHDQAEUNN6C

Then I substituted the ID into the string Nikel provided from Operation Ardent
ScenEdit_SetUnitSide({side='China', guid='LK465H-0HN7TERUINFMT', newside='Singapore'})

and created
ScenEdit_SetUnitSide({side='Red', guid='MTJZF8-0HNHDQAEUNN6C', newside='Blue'})

Re-run the scenario and it changed on the timer. I was able to access Aircraft Operations.

Appreciate the assistance everyone.
I'll be reading the thread that SunlitZelkova provided.
Post Reply

Return to “Command: Modern Operations series”