quote:
Can I reuse the retval part to have a second Input box? and from there to the function InitiateBioContact(Dist1,BioDbid) ??
Sure. Entire thing tested sample...
function InitiateBioContact(Dist1,BioDBID)
local ZZUnit = ScenEdit_GetUnit({guid='50PVO4-0HMD7C9VFQET3'});
local Brg1 = ZZUnit.heading; -- is recht vooruit
local pt = World_GetPointFromBearing({LATITUDE=ZZUnit.latitude,LONGITUDE=ZZUnit.longitude,BEARING=Brg1, DISTANCE=Dist1});
ScenEdit_AddUnit({side='Nature', Type='Submarine', Name='Fish', dbid=BioDBID, lat=pt.latitude,lon=pt.longitude, Heading=030, manualSpeed=3, manualAltitude='underlayer'});
end
function GetNumberFromUser(displaytext,minnum,maxnum,errornum)
local retval = ScenEdit_InputBox(displaytext);
if (retval ~=nil) and retval ~="" then -- "" is a user pressing cancel.
retval = tonumber(retval); --attempt convert.
if retval ==nil then return errornum; end -- not point to continue if it failed. (ie converting abc32 produces nil)
else
return errornum; --was already nil or emptystring.
end
if retval >= minnum and retval <= maxnum then return retval; end --valid so return the number.
return errornum; -- if we get here it was a number but was out of range.-- failed validation
end
local function firstQuestion()
local trycount,retval = 0,0;
while (retval == 0) do --keep looping till we get a non-zero number or hit 5 bad attempts.
if trycount > 4 then
retval = 1; --person is dumb or there is numerical conversion problem, use a default or swap this for random#
break; --break the looping after 5 attempts.
else
trycount = trycount+1
retval = GetNumberFromUser('1: 2.0nm\r2: 4.0nm\r3: 7.0nm\r\nEnter the number of your choice',1,3,0);
end
--reuse and change retval to the chosen distance based on selection
if retval == 1 then retval = 2.0 --if the selection was valid and #1
elseif retval==2 then retval = 4.0 -- if the selection was valid and #2
elseif retval==3 then retval = 7.0 -- if the selection was valid and #3
end
end
return retval;
end
local function secondQuestion()
local trycount,retval = 0,0;
while (retval == 0) do
if trycount > 4 then retval = 354; break; --default to a dbid.
else
trycount = trycount+1;
retval = GetNumberFromUser('1: Fish School\r2: Orca\r3: Whale\r\nEnter the number of your choice',1,3,0);
end
--reuse and change retval to the chosen distance based on selection
if retval == 1 then retval = 354;--if the selection was valid and #1
elseif retval==2 then retval = 355;-- if the selection was valid and #2
elseif retval==3 then retval = 92;-- if the selection was valid and #3
end
end
return retval;
end
InitiateBioContact(firstQuestion(),secondQuestion())
Hope that helps show you how you can a) do it, b) learn and extend from it.