Jump to content

Recommended Posts

Posted

Hi Guys,

 

I am interested to test if a group exist and wanted to use the isExist function but I am running into trouble :

 

if Group.getByName('whatever'):isExist() then
     trigger.action.outText("Exist", 10)
else 
     trigger.action.outText("Does NOT exist !!!", 10) 
end

This works fine if the group exists but gives an error if it doesn't :joystick:

What am I doing wrong ?

Isn't the isExist function supposed to tell you if a group exist or not...

Obviously if it doesn't the getbyName will return nil but isExist is complaining :cry::joystick:

 

Thanks

Posted

You don't actually need the isExist operator.

 

if Group.getByName('whatever') then
     trigger.action.outText("Exist", 10)
else 
     trigger.action.outText("Does NOT exist !!!", 10) 
end

 

Will work just fine.

Posted

if Group.getByName('whatever'):isExist() then
     trigger.action.outText("Exist", 10)
else 
     trigger.action.outText("Does NOT exist !!!", 10) 
end

What am I doing wrong ?

if [b]Group.getByName('whatever') and[/b] Group.getByName('whatever'):isExist() then
     trigger.action.outText("Exist", 10)
else 
     trigger.action.outText("Does NOT exist !!!", 10) 
end

I'd do it this way. You cannot call a function (isExist here) on an object that is nil.

A warrior's mission is to foster the success of others.

i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3

RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

Posted

Hello,

 

 

I do agrre qith you all...

But what is the prupose of isExit....

 

Really I think it is useless if it cannot telle you that a unti does not exist...

But may be I am missing something there...

Posted

For groups and units it is just another way to test if an object is currently present. If you stored the object and you know its name, it doesn't really matter if you use isExist() or getByName() since they have the same result more or less.

 

Group.getByName('whatever'):isExist() might not work because it could be read as nil:isExist()

 

Something like this would work if you periodically ran the checkIsExist function call. That is assuming the group object was correctly returned when you defined it.

 

local gp = Group.getByName('whatever')
local function checkIsExist()
 if gp:isExist() == false then
 -- group ded
end 
end

 

 

However if you are working with tracking weapons or scenery objects then you can only use isExist() to check the status of that specific object. For example the FC3 MP mission "Sukhoi Surprise" has a script in there to track bombs and where they land. Part of the code is it uses a shot event handler to get each bomb's object which adds that data to a table and iterates each bomb updating the position data to get an impact point. When the bomb no longer exists it uses the last known position data for the impact point then if it is inside a polyzone it to a score for the airbase segment hit.

 

   local function track_wpns()
       mist.scheduleFunction(track_wpns, {}, timer.getTime() + 0.05)  -- reschedule first
       
       for wpn_id_, wpnData in pairs(tracked_wpns) do
           if wpnData.wpn:isExist() then  -- just update position and direction.
               wpnData.pos = wpnData.wpn:getPosition().p
               wpnData.dir = wpnData.wpn:getPosition().x
           else -- wpn no longer exists, must be dead.
               tracked_wpns[wpn_id_] = nil -- remove from tracked weapons first.
               local ip = land.getIP(wpnData.pos, wpnData.dir, 20)  -- terrain intersection point with weapon's nose.  Only search out 20 meters though.
               local impactPoint
               if not ip then -- use last position
                   impactPoint = wpnData.pos
               else -- use intersection point
                   impactPoint = ip
               end
               for i = 1, #segmentPolys do
                   if mist.pointInPolygon(impactPoint, segmentPolys[i]) then -- weapon impacted in runway segment!
                       runwayHits[i][#runwayHits[i] + 1] = wpnData.init
                   end
               end
           end
       end
   end

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...