0 Members and 1 Guest are viewing this topic.
Il recoit apr contre des données à un format plus "cfg orbiter" car pour l'instant je les édite à la main. le xml ne me sert que quand je discute entre deux modules et que j'ai aps à traiter des trucs à al main.
Execute a Lua command or script from a module using the Orbiter API. This is useful for implementing autopilots and control systems.For script examples and a list of available functions, see the “Orbiter Scripting User Manual” section in the Orbiter online help (available from the “Help” button on the Launchpad window, or with from within the simulation. From a terminal (console window or terminal MFD) you can access the script manual by typing: help(api).
lua est un super langage de script. et cela peux simplifier pas mal de choses pour ce que tu veux faire pour le mode carrière
-- read high score list from filefunction hscore_read (file,n) local slist={} local f = io.open(file,"r") if f ~= nil then for i=1,n do local t = f:read() if t == nil then break end local name,fuel _,_,name,fuel = string.find (t, "(.-):(.+)") slist[i]={name,tonumber(fuel)} end f:close() end return slistend-- write high score list to filefunction hscore_write (file,hscore) local f = io.open(file,"w") for i=1,#hscore do f:write(hscore[i][1]..':'..hscore[i][2]..'\n') end f:close()end-- convert high score list to a stringfunction hscore2str (hscore,mark) local str if #hscore > 0 then str = 'High score list:\n\n'..string.format('%s %s', 'Fuel used', 'Name')..'\n----------------------------------' for i=1,#hscore do str = str..'\n'..string.format('%08.2f %s', hscore[i][2], hscore[i][1]) if mark==i then str = str..' <====' end end else str = 'No high scores yet!' end return strenddata_path = 'Script/Challenges/Challenge1.dat' -- high score filemax_score = 10 -- max high score entriesintro = 'Flight challenge:\n\Launch the Delta-glider into orbit and dock\with the International Space Station.\Use as little fuel as possible.\n'term.out (intro)-- read highscore listslist = hscore_read (data_path, max_score)-- sanity checksv = vessel.get_interface('GL-01')if v == nil then term.out ('Could not find GL-01. Aborting') returnelseif v:get_classname() ~= 'DeltaGlider' then term.out ('Wrong vessel class. Aborting') returnendhd = v:get_dockhandle (0)hp0 = v:get_propellanthandle (0) -- main tankhp1 = v:get_propellanthandle (1) -- RCS tankm0 = 13500m1 = v:get_propellantmass (hp0) + v:get_propellantmass (hp1)if m0 == m1 then ptext = string.format ("Initial propellant mass: %.2f kg\n", m0)else ptext = string.format ("Initial propellant mass: %.2f kg\nUsed so far: %.2f kg\n", m0, m0-m1)endhtext = hscore2str(slist)term.out(ptext..'\n'..htext..'\n')note = oapi.create_annotation()note:set_pos (0.3,0.05,0.9,0.95)note:set_colour ({r=1,g=0.6,b=0.2})note:set_text (intro..'\n'..ptext..'\n'..htext)-- wait for engineswhile v:get_propellantmass (hp0) + v:get_propellantmass(hp1) == m1 do proc.skip() if m1 < m0 and oapi.get_simtime() > 10 then break endendnote:set_pos (0.05,0.2,0.5,0.5)note:set_size (1.2)-- wait for docking eventmate = v:get_dockstatus (hd)while mate==nil do dm = m0 - (v:get_propellantmass (hp0) + v:get_propellantmass(hp1)) note:set_text (string.format("Fuel used: %.2f kg", dm)) proc.skip() mate = v:get_dockstatus (hd) if mate ~= nil then -- make sure we are docked to ISS v2 = vessel.get_interface(mate) if v2:get_name()~='ISS' then mate = nil end endend-- write out the resultsdm = m0 - (v:get_propellantmass (hp0) + v:get_propellantmass(hp1))ptext = "Challenge completed successfully!\n"ptext = ptext..string.format ("Total fuel expenditure: %.2f kg", dm)note:set_pos (0.3,0.15,0.9,0.95)note:set_size (1)note:set_text (ptext)-- enter high score list!if #slist<max_score or dm < slist[#slist][2] then ptext = ptext.."\n\nYou made it into the high score!" note:set_text (ptext) name = proc.wait_input ('High score: Enter your name:') idx = #slist+1 for i = 1,#slist do if slist[i][2] > dm then idx=i; break end end table.insert(slist,idx,{name,dm}) if #slist > max_score then table.remove(slist) end hscore_write (data_path, slist)endptext = ptext..'\n\n'..hscore2str(slist,idx)note:set_text (ptext)proc.wait_sysdt(20)oapi.del_annotation (note)