Stonehouse Posted September 18, 2015 Posted September 18, 2015 Can't find this in any reference docs so far so asking here. I have a do loop that is something like for j = z, #table do and z is a calculated value. If the value of z is < zero what happens? Inside the loop the table elements for j are being retrieved as well - so I assume if the for statement somehow works then the table elements for say j = -1 will be nil on retrieval? I believe that the table itself is either empty or has indexes greater than 0 when being built. It also looks to me like the calc of z is trying to prevent z ending up zero as it's #table - max chosen for table + 1. However as #table is built up by things spawning until it hits max chosen I think z could be less than 0 early on in the mission. eg max chosen = 4 so until the 4th group spawns z would be less than 0 and when the 4th group spawns it would be 1. Thanks, Stonehouse
Grimes Posted September 18, 2015 Posted September 18, 2015 By default it will start at whatever value z is and count up by 1 to the size of table. Since you are deriving z from the size of table and are using j to reference a specific index of the table, it is entirely possible that nothing will be return if no table entry exists at negative values or 0. It is a little difficult to visualize specifically what you are trying to do with it without seeing at least a code fragment. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Stonehouse Posted September 18, 2015 Author Posted September 18, 2015 (edited) Sorry Grimes example below. Trying to track down the CAP spamming issues in GCICAP. I believe #actualCAPtable will either be 0 or greater than 1 and it contains the CAP flight information with one entry per CAP group. numstatusCAPgrps is the factions max number of CAP groups chosen by the mission designer and configured in the script as part of setting it up. CAPside is the faction being dealt with at that particular time ie red or blue z = #actualCAPtable[CAPside] - numstatusCAPgrps + 1 for j = z, #actualCAPtable[CAPside] do if debuggingmessages == true and (CAPside == debuggingside or debuggingside == 'both') and (funnum == 0 or funnum == 6) then Debug("debuggingmessage CAPStatusCheck: script hung C-X1: counter:"..string.format(counter).."/ CAPside: "..CAPside, CAPside) end if Group.getByName(actualCAPtable[CAPside][j].groupname) ~= nil blah blah So if z was < 0 would the loop iterate? sounds like yes and from what you said the Group.getByName would return a nil group name if the entries in actualCAPtable ran from 1 to whatever? I guess this is actually a table related question not a loop one. Thanks, Stonehouse Edited September 18, 2015 by Stonehouse
Grimes Posted September 18, 2015 Posted September 18, 2015 Could always add temporary env.info() calls to get an idea of what values are being passed. But I'm quite certain the for loop can start below 0. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Recommended Posts