Getting Highlighted Reference Points

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
bearhunter007
Posts: 23
Joined: Sat Mar 11, 2017 2:51 am

Getting Highlighted Reference Points

Post by bearhunter007 »

The code below works as far as getting the number of Reference points and whether they are highlighted. It fails on the logic test of whether zz='Yes'. What am I missing?



--Get all Highlighted Reference Points
local u = VP_GetSide({Side ='Vietnam'}) -- a side object
--print(u.rps)

tbl={}
tbl=u.rps
--print(tbl)
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
print(count)


for i=1, count do
if u.rps~=nil then
local zz=u.rps.highlighted
print(zz)
if zz=='Yes' then
print(u.rps) -- ***This is not getting printed***
end
end
end
Eboreg
Posts: 255
Joined: Wed Mar 13, 2019 10:35 pm

RE: Getting Highlighted Reference Points

Post by Eboreg »

Change "if zz == 'Yes'" to "if zz == true"
bearhunter007
Posts: 23
Joined: Sat Mar 11, 2017 2:51 am

RE: Getting Highlighted Reference Points

Post by bearhunter007 »

Eboreg

Thanks for the reply. I initially tried 'true' but it did not work.

User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Getting Highlighted Reference Points

Post by michaelm75au »

Simple test to validate
local a = ScenEdit_GetReferencePoint({side='1',name='rp-7'})
print(a.highlighted)
if a.highlighted == true then
print('Highlighted')
end
Michael
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Getting Highlighted Reference Points

Post by michaelm75au »

BTW, when printing 'boolean' types, they usually come out 'Yes' or 'No'. But you test them against proper values (true/false)
Michael
bearhunter007
Posts: 23
Joined: Sat Mar 11, 2017 2:51 am

RE: Getting Highlighted Reference Points

Post by bearhunter007 »

Thanks Michael I realized I had several syntax errors.

Here is the corrected code that works:

--Get all Highlighted Reference Points
local u = VP_GetSide({Side ='Vietnam'}) -- a side object
--print(u.rps)

tbl={}
tbl=u.rps
--print(tbl)
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
print(count)


for i=1, count do
if u.rps~=nil then
local z=u.rps.highlighted==true
if z==true then print(u.rps) end
end
end
Post Reply

Return to “Lua Legion”