Page 1 of 1

Getting Highlighted Reference Points

Posted: Thu Mar 19, 2020 7:07 pm
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

RE: Getting Highlighted Reference Points

Posted: Thu Mar 19, 2020 9:49 pm
by Eboreg
Change "if zz == 'Yes'" to "if zz == true"

RE: Getting Highlighted Reference Points

Posted: Thu Mar 19, 2020 11:28 pm
by bearhunter007
Eboreg

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


RE: Getting Highlighted Reference Points

Posted: Fri Mar 20, 2020 12:27 am
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

RE: Getting Highlighted Reference Points

Posted: Fri Mar 20, 2020 12:29 am
by michaelm75au
BTW, when printing 'boolean' types, they usually come out 'Yes' or 'No'. But you test them against proper values (true/false)

RE: Getting Highlighted Reference Points

Posted: Fri Mar 20, 2020 3:15 pm
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