Condition Event

Moderators: Dandin384, Kushan, ckfinite

Condition Event

Postby wqc12345 » Fri Jul 29, 2016 7:53 pm

Does anyone know how to create a condition that evaluates to TRUE for the condition in Lua. Right now, we can set a posture condition, but I wanted to set a condition that indicates if a UNIT is alive, then TRUE, otherwise, FALSE and have that eval in the condition like the side postures does.. but its not clear to me how the mechanism works inside CMANO? Meaning, will the lua return either TRUE or FALSE?

Like this:

unit=ScenEdit_GetUnit({side="NK", name="Tonghae Missile Launch Pad (Nudong-2 On Pad)"})
if unit==nil
then
return 1
else
return 0
end

But, it doesn't seem to be working?? Any ideas?
wqc12345
 
Posts: 7
Joined: Sun Jun 19, 2016 8:43 pm

Re: Condition Event

Postby michaelm » Sat Jul 30, 2016 4:13 am

If you are referring to a event condition, then you need to return true or false as in

--
if tests evaluate as true
return true
else
return false
--
or set a variable at the start, and the do stuff that could change it
local answer = true;
....
return (answer);
michaelm
 
Posts: 12
Joined: Tue May 03, 2016 11:19 am

Re: Condition Event

Postby wqc12345 » Mon Aug 01, 2016 9:48 pm

Thanks Michael, then this would evaluate to TRUE or FALSE for the condition?

once I return TRUE or FALSE, it will evaluate that condition correctly? like posture?

We are talking about the same thing, correct? I'm talking about the "lua script" option for scenario conditions, which only include posture change and scenario start.

Thanks,
wqc12345
 
Posts: 7
Joined: Sun Jun 19, 2016 8:43 pm

Re: Condition Event

Postby wqc12345 » Mon Aug 01, 2016 11:27 pm

local function tf(unitin)
print(unitin)
unit=ScenEdit_GetUnit({side="NK", name=unitin})
print(unit)
if unit==nil
then
return FALSE
else
return TRUE
end
end

tf("Tonghae Missile Launch Pad 1")

answer=tf("Tonghae Missile Launch Pad 2")
print(answer)

tf("Tonghae Missile Launch Pad 2")

answer=tf("Tonghae Missile Launch Pad 2")
print(answer)
Tonghae Missile Launch Pad 2
nil
Tonghae Missile Launch Pad 2
nil
nil
>> local function tf(unitin)
print(unitin)
unit=ScenEdit_GetUnit({side="NK", name=unitin})
print(unit)
if unit==nil
then
return FALSE
else
return TRUE
end
end

tf("Tonghae Missile Launch Pad 1")

answer=tf("Tonghae Missile Launch Pad 1")
print(answer)
Tonghae Missile Launch Pad 1
{
type = 'Facility',
name = 'Tonghae Missile Launch Pad 1',
latitude = '40.8557467055114',
longitude = '129.665909670942',
altitude = '35',
autodetectable = 'False',
side = 'NK',
guid = '40f7d8b8-dbbe-4e19-ad2e-30f0a1aeac6e',
group = 'Tonghae Missile Launch Site',
mission = 'Nuclear Strike',
}
Tonghae Missile Launch Pad 1
{
type = 'Facility',
name = 'Tonghae Missile Launch Pad 1',
latitude = '40.8557467055114',
longitude = '129.665909670942',
altitude = '35',
autodetectable = 'False',
side = 'NK',
guid = '40f7d8b8-dbbe-4e19-ad2e-30f0a1aeac6e',
group = 'Tonghae Missile Launch Site',
mission = 'Nuclear Strike',
}
nil

Note, that in one case, Tonghae 2 = DOESN'T EXIST and Tonghae 1 = DOES EXIST.

For both, I'm getting a NIL value on the return? What am I doing wrong here?
wqc12345
 
Posts: 7
Joined: Sun Jun 19, 2016 8:43 pm

Re: Condition Event

Postby michaelm » Tue Aug 02, 2016 9:47 am

okay, you talking about functions in general. My mistake.
1. use lower case true and false
2. the function converts the true/false to 'Yes'/'No' on return to the script. You still need to treat this as true/false when testing.

>> local function tf(unitin)
print('TF=' .. unitin)
unit=ScenEdit_GetUnit({side="NK", name=unitin})
print(unit)
if unit==nil
then
return false
else
return true
end
end

answer=tf("Tonghae Missile Launch Pad 2")
print('result = ');print(answer)
if answer == false then
print('tf returned false')
elseif answer == true then
print('tf returned true')
end
---result----
TF=Tonghae Missile Launch Pad 2
nil
result =
'No'
tf returned false

--
Hope this is clearer.
michaelm
 
Posts: 12
Joined: Tue May 03, 2016 11:19 am

Re: Condition Event

Postby wqc12345 » Tue Aug 02, 2016 5:38 pm

Thanks michael.. code worked, but it did not work in game.

I only want the event to fire if the unit exists still, so, this will resolve to true if the pad is still there..but it's indicating that the condition failed.. which is very confusing to me.

can you do a similar function for a unit "still" in an area. I'm not sure how I would do this? meaning, if a unit is still within in rect then true otherwise false?
wqc12345
 
Posts: 7
Joined: Sun Jun 19, 2016 8:43 pm

Re: Condition Event

Postby michaelm » Wed Aug 03, 2016 10:27 am

Saw your post and commented in it.
Looks like my second post wasn't clear.
You need to 'return' something to the Event condition -true or false - to let the event know how to proceed.
michaelm
 
Posts: 12
Joined: Tue May 03, 2016 11:19 am

Re: Condition Event

Postby wqc12345 » Wed Aug 03, 2016 3:21 pm

Michael, I'm still confused. What code would work for a unit of still present would return true? That's really what I need for the condition
wqc12345
 
Posts: 7
Joined: Sun Jun 19, 2016 8:43 pm

Re: Condition Event

Postby michaelm » Thu Aug 04, 2016 2:14 pm

This would be condition code:
---
local function tf(unitin)
unit=ScenEdit_GetUnit({side="NK", name=unitin});print(unit)
if unit==nil
then
return false
else
return true
end
end

local answer=tf("Tonghae Missile Launch Pad 1");print(answer)
return answer

--
michaelm
 
Posts: 12
Joined: Tue May 03, 2016 11:19 am



Return to Command Lua




Users browsing this forum: No registered users and 3 guests

cron