celem Posted April 1, 2015 Share Posted April 1, 2015 (edited) Hmm. Do you really mean any tank?The typical solution is IF STAGE:LIQUIDFUEL < 0.01 {STAGE.}This checks to see if all engines in the current stage are empty and drops if they are. The 0.01 is because KSP doesnt always empty big tanks. Im not sure how this behaves with asparagus staging, whether the radial tanks are considered same stage as the core booster. It also obviously only works on LF engines. Works well as a WHEN THEN trigger.If you specifically want as you stated: If any LF tank anywhere on the ship is empty, then stage:You probably need Lists. Off the top of my head something like: list tanks in tanklist. for t in tanklist {if t:liquidfuel < 0.01 {stage.}}.Not tested that one but it should walk the entire ship and check each tank, calling stage everytime it finds an empty, if you have a bunch of empty tanks this would dissassemble your ship, but you see what i mean... Set a boolean flag true when you find empties and stage when true, would work for asparagus and slack tank setups i guess.Personally I use: set nO to 0. list engines in el. for e in el { if e:flameout { set nO to nO + 1. } }IF nO > 0 {STAGE.}Stages if anything is 'flamed-out', which includes not just jet engines but absolutely any motor that is resource starved, so works for solids/ions/any mod fuels and is immune to the residual fuel-traces which can muck with staging logic. The disadvantage of the two list methods is that they kinda need to be inside your loops and dont work as WHEN triggers, and the last one absolutely cannot handle a slack tank since its actually inspecting engines. Edited April 1, 2015 by celem typos in code sections Link to comment Share on other sites More sharing options...
jandcando Posted April 1, 2015 Share Posted April 1, 2015 Hello everyone! I'm here to let you know that I just started a little project on GitHub for a Notepad++ language file for kOS. I'm pretty sure I have the basics down already, but I know there are some holes. I would like it if people started using this so they can tell me the holes, or maybe fix them themselves.You can try it out here. Link to comment Share on other sites More sharing options...
avi Posted April 1, 2015 Share Posted April 1, 2015 By the way, I talked to erendrake and confirmed that LOCK STEERING does not properly use engine gimbaling, so if you intend to use this mod in say, Realism Overhaul, you're going to have to resort to using Raw Input. Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 Hello everyone! I'm here to let you know that I just started a little project on GitHub for a Notepad++ language file for kOS. I'm pretty sure I have the basics down already, but I know there are some holes. I would like it if people started using this so they can tell me the holes, or maybe fix them themselves.You can try it out here.It has been done in the past, but your version may be more up-to date if you keep maintaining it. Link to comment Share on other sites More sharing options...
Dunbaratu Posted April 1, 2015 Share Posted April 1, 2015 By the way, I talked to erendrake and confirmed that LOCK STEERING does not properly use engine gimbaling, so if you intend to use this mod in say, Realism Overhaul, you're going to have to resort to using Raw Input.Then why do I remember over and over again seeing the engine nozzles tilting back and forth as kOS yanks the controls back and forth (in its overzealous way)? I know I've seen it do this a lot, but then again I don't play under RO. Is it a specific thing the RO mod does to change the API for gimbals?As far as I knew, kOS lock steering merely yanks the "joystick" WASDQE controls around, and lets the main KSP game engine do whatever it will with those inputs, without making any fancy exceptions. The main game gimbals when you use WASDQE, so why doesn't kOS when it does? Link to comment Share on other sites More sharing options...
Kamik423 Posted April 1, 2015 Share Posted April 1, 2015 Can anyone recommend a way to do the following:If any liquid fuel tank is empty, stage.Or you could use it on combination with smart parts to take pressure off kOS. Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 (edited) list tanks in tanklist. for t in tanklist {if t:liquidfuel < 0.01 {stage.}}.Ah this was the sort of thing I was looking for, just couldn't get my head around it. Thanks. The 'standard' WHEN STAGE:LIQUIDFUEL < 0.001 only seems to work for very simple fuel setups.I'm still having trouble building a tanklist that contains a list of fuel tanks. I've tried this:set TANKLIST to SHIP:MODULESNAMED("fueltank")But it doesn't seem to match anything.So now I've got something like this:SET tanklist to SHIP:PARTSDUBBED("fueltank"). for t in tanklist { if t:RESOURCES:LIQUIDFUEL:AMOUNT < 0.01 { STAGE. } }But apparently t:RESOURCES:LIQUIDFUEL:AMOUNT is wrong. How do I get the amount of liquid fuel left in a part? Edited April 1, 2015 by Sonny_Jim Link to comment Share on other sites More sharing options...
ManTrelk Posted April 1, 2015 Share Posted April 1, 2015 I'm so confused... New to kOS here. The command LOCK STEERING TO R(0,0,0) should keep the ship pointing in whatever direction it's currently facing, right? No rotation about its axis or anything as a result of that command?The command LOCK STEERING TO HEADING (SHIP:FACING:ROLL,90) should also result in no change to roll, right? Why does it make my ship do a 360 degree roll? How can I avoid this and lock steering without changing my ship's roll??More to the point though, is something wrong with how kOS handles changes to a ship's roll value? My vessels seem to shift on other axes when I give it a command to change its roll (which is why I'm trying get it to maintain its current roll...). Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 (edited) Ah this was the sort of thing I was looking for, just couldn't get my head around it. Thanks. The 'standard' WHEN STAGE:LIQUIDFUEL < 0.001 only seems to work for very simple fuel setups.I'm still having trouble building a tanklist that contains a list of fuel tanks. I've tried this:But it doesn't seem to match anything.There are a lot of ways to trigger stages, and not all of them require resource monitoring. For example see the next snippet:set stagemaxthrust to ship:maxthrust.when status <> "PRELAUNCH" and (ship:maxthrust<stagemaxthrust or ship:maxthrust<1) then { print "Stage!". stage. set stagemaxthrust to ship:maxthrust. preserve.}You remember ship's maxthrust and stage when it changes (due to engine flameout). The example I provided works with asparagus staging design- - - Updated - - -I'm so confused... New to kOS here. The command LOCK STEERING TO R(0,0,0) should keep the ship pointing in whatever direction it's currently facing, right? No rotation about its axis or anything as a result of that command?The command LOCK STEERING TO HEADING (SHIP:FACING:ROLL,90) should also result in no change to roll, right? Why does it make my ship do a 360 degree roll? How can I avoid this and lock steering without changing my ship's roll??More to the point though, is something wrong with how kOS handles changes to a ship's roll value? My vessels seem to shift on other axes when I give it a command to change its roll (which is why I'm trying get it to maintain its current roll...).It seems you are confusing ROLL and compass. In HEADING(x,y) parameter x is the compass direction (http://ksp-kos.github.io/KOS_DOC/commands/flight/cooked.html?highlight=heading)It is not kOS way of handling, but more of a how UnityEngine handles directions. If you want your ship keep a steady roll during ascend consider the following code snippet:lock steering to lookdirup(up:vector, ship:facing:topvector).Or as a part of the loop:until altitude > ha or apoapsis > orbitAlt { set ar to alt:radar. // control attitude if ar < gt0 { set arr to ar / gt0. set pda to (cos(arr * 180) + 1) / 2. set pitch to pitch0 * ( pda - 1 ). set pitchvector to up + R(0, pitch, 0). lock steering to lookdirup(pitchvector:vector, ship:facing:topvector). } Edited April 1, 2015 by Ziw Link to comment Share on other sites More sharing options...
JD_Tiger Posted April 1, 2015 Share Posted April 1, 2015 Tryed my script got following error:Get suffix'DOEVENT' not found on objet LIST of 3 itemsAny idea what I can do?Script: https://drive.google.com/file/d/0BypxFvfIp362RDNFU2JoWUtJWHM/view?usp=sharing*Push* Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 The example I provided works with asparagus staging designHow? From what I see it only stages when an engine flames out, not when a tank is emptied, which is what I'm trying to do. Link to comment Share on other sites More sharing options...
ManTrelk Posted April 1, 2015 Share Posted April 1, 2015 Thanks for the reply. I don't really mind changing the roll if the ship does it smoothly without deviating off its roll axis. Just to clarify, is that an artefact of UnityEngine or were you referring to the 360 degree roll I experience?That first bit of code you posted keeps the roll steady, but locks the ship to UP. Is there a way to get one without the other?Also, is gt0 an undefined variable in the until loop? Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 Ok, so I've managed to figure out a way to check for resources in a partslist that's made up of fuel tanks:SET tanklist to SHIP:PARTSDUBBED("fueltank").for t in tanklist {if t:resources[0]:AMOUNT < 0.01 {STAGE.}}What I'd like to do now is to build a parts list containing all the fuel tanks by seeing if they have a LIQUIDFUEL resource, rather than finding them by a part name:for i in SHIP:PARTS { if i:RESOURCES:CONTAINS ("LIQUIDFUEL") { tanklist:ADD (t). }}But again I'm running into syntax problems. Could someone post a way to build a list of all parts that contain liquidfuel as a resource? Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 (edited) How? From what I see it only stages when an engine flames out, not when a tank is emptied, which is what I'm trying to do.Sorry, it works not for every type of asparagus staging, but only where engine flameout means there is need to stage.- - - Updated - - -*Push*Better post code here.In your codePRINT "Deploying Payload".STAGE.SET ANTENNA TO SHIP:PARTSTAGGED("Comms").ANTENNA:DOEVENT("activate").ANTENNA is not a PartModule, it is a Part. You need to get the PartModule corresponding to your antenna.If you are using RemoteTech that would be accessed as set antenna_pm to ANTENNA:getmodule("ModuleRTAntenna").After that you may call antenna_pm:doevent("activate").- - - Updated - - -Ok, so I've managed to figure out a way to check for resources in a partslist that's made up of fuel tanks:What I'd like to do now is to build a parts list containing all the fuel tanks by seeing if they have a LIQUIDFUEL resource, rather than finding them by a part name:But again I'm running into syntax problems. Could someone post a way to build a list of all parts that contain liquidfuel as a resource?http://ksp-kos.github.io/KOS_DOC/language/flow.html#forhttp://ksp-kos.github.io/KOS_DOC/structures/vessels/resource.html#structure:RESOURCE- - - Updated - - -Thanks for the reply. I don't really mind changing the roll if the ship does it smoothly without deviating off its roll axis. Just to clarify, is that an artefact of UnityEngine or were you referring to the 360 degree roll I experience?That first bit of code you posted keeps the roll steady, but locks the ship to UP. Is there a way to get one without the other?Also, is gt0 an undefined variable in the until loop?I posted just a fraction of the ascend script as an example of how to keep the rocket pointing where you want it to, while keeping the roll stable. It is not that hard to figure out. Try finishing my second part by setting up missing variables. gt1 is the altitude of the first part of the ascend, during which you need to do the initial pitchover maneuver. It depends on your design and whether or not you're using FAR, but set it to say 5000 and set pitch0 to say 5 and see how your rocket behaves. Edited April 1, 2015 by Ziw Link to comment Share on other sites More sharing options...
JD_Tiger Posted April 1, 2015 Share Posted April 1, 2015 In your codePRINT "Deploying Payload".STAGE.SET ANTENNA TO SHIP:PARTSTAGGED("Comms").ANTENNA:DOEVENT("activate").ANTENNA is not a PartModule, it is a Part. You need to get the PartModule corresponding to your antenna.If you are using RemoteTech that would be accessed as set antenna_pm to ANTENNA:getmodule("ModuleRTAntenna").After that you may call antenna_pm:doevent("activate"). Ok, clear now...Will try and report... Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 I know how to use FOR, it's just I don't know what the syntax is to check if a part contains a liquidfuel resource. Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 Use FOR loop to look through PART:RESOURCES and set a flag if it contains the resource you need. Link to comment Share on other sites More sharing options...
JD_Tiger Posted April 1, 2015 Share Posted April 1, 2015 (edited) Yeah! new failure:Code:PRINT "Deploying Payload".STAGE.SET ANTENNA TO SHIP:partstagged("Comms").SET ANTENNA_PM TO ANTENNA:GETMODULE("ModuleRTAntenna").ANTENNA_PM:doevent("activate"). Edited April 1, 2015 by JD_Tiger Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 Use FOR loop to look through PART:RESOURCESBut how? I tried using CONTAINS and I got a syntax error. The closest I've got so far is to check whether the part has more than one resource:SET tanklist to LIST().for i in SHIP:PARTS { if i:RESOURCES:length > 1 { tanklist:ADD (i). }} Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 This means that Antenna in your script is not a Part, but a list of parts. To access a particular part use ANTENNA[0] , ANTENNA[1] and etc Link to comment Share on other sites More sharing options...
JD_Tiger Posted April 1, 2015 Share Posted April 1, 2015 (edited) So i have to write 3 lines to activate all right?like so:PRINT "Deploying Payload".STAGE.SET ANTENNA TO SHIP:PARTSTAGGED("Comms").SET ANTENNA_PM TO ANTENNA[0]:GETMODULE("ModuleRTAntenna").ANTENNA_PM:DOEVENT("activate").SET ANTENNA_PM TO ANTENNA[2]:GETMODULE("ModuleRTAntenna").ANTENNA_PM:DOEVENT("activate").SET ANTENNA_PM TO ANTENNA[1]:GETMODULE("ModuleRTAntenna").ANTENNA_PM:DOEVENT("activate"). Edited April 1, 2015 by JD_Tiger Link to comment Share on other sites More sharing options...
Ziw Posted April 1, 2015 Share Posted April 1, 2015 (edited) JD_Tiger:Yes, if you have 3 antennas. But I see some of them are Dishes and you will also need to target them manually - there is no way to do it via kOS right now.Sonny_Jim: set fuelTanks to List().for i in ship:parts{ for i1 in i:resources { if i1:name = "LIQUIDFUEL" { fuelTanks:ADD(i). break. } }}I spent 3.5 minutes writing this, it is not that hard to create a workaround for CONTAINS Edited April 1, 2015 by Ziw Link to comment Share on other sites More sharing options...
Sonny_Jim Posted April 1, 2015 Share Posted April 1, 2015 it is not that hard to create a workaround for CONTAINS If you know how the syntax works and have an example to work from sure it's a lot easier. Thanks. Link to comment Share on other sites More sharing options...
stevehead Posted April 1, 2015 Share Posted April 1, 2015 I've noticed today that when using STAGE:LIQUIDFUEL with an Interstage Fairing Adapter from Procedural Fairings acting as a decoupler between my stages, kOS will calculate the amount of fuel in the current stage and the stage above it. Therefore, the following staging code is never executed:WHEN stage:liquidfuel < 0.1 THEN { STAGE.}.For example, say stage 1 has 500 liquid fuel and stage 2 has 100 liquid fuel... when I do PRINT STAGE:LIQUIDFUEL as soon as I launch the rocket, it will output 600, and when stage 1 has used all of its fuel, it will output 100. Link to comment Share on other sites More sharing options...
Dunbaratu Posted April 1, 2015 Share Posted April 1, 2015 I've noticed today that when using STAGE:LIQUIDFUEL with an Interstage Fairing Adapter from Procedural Fairings acting as a decoupler between my stages, kOS will calculate the amount of fuel in the current stage and the stage above it. Therefore, the following staging code is never executed:WHEN stage:liquidfuel < 0.1 THEN { STAGE.}.For example, say stage 1 has 500 liquid fuel and stage 2 has 100 liquid fuel... when I do PRINT STAGE:LIQUIDFUEL as soon as I launch the rocket, it will output 600, and when stage 1 has used all of its fuel, it will output 100.kOS used to use its own complex parts walk algorithm to find all the fuel. Now it just relies on KSP's own API for it. Is there a discrepancy between the fuel shown in the indicators on the side and what kOS says? I.e. when it says there's 100 units left, are the green indicators all empty, or do they also show fuel left? If they also show fuel left then there's not much we can do - that means KSP itself thinks there's fuel for some of the active engines.If it is showing zero fuel in the indicators when kOS says 100, can you show a screenshot of the game, showing where the 100 units of fuel are coming from (highlight the tank it is counting that it shouldn't be and show the popup for it if you can)? It's hard to diagnose from just the verbal description. Link to comment Share on other sites More sharing options...
Recommended Posts