Jump to content

Creating procedural science experiments


Recommended Posts

Hello everyone,

what I'm trying to do is to generate some information during flight and then present it as a science experiment.

I'm trying to figure out how to use the ScienceExperiment class, but I can't really understand how it works: has anybody ever done the same?

Link to comment
Share on other sites

It depends on what exactly you mean by procedural.

The default ModuleScienceExperiment won't really be of any help here, at least not for what I think you're getting at.

The closest thing I can think of to what you describe is SCANsat. It assigns science value based on scanning coverage, basically taking some information from what you've scanned so far, making some calculations to come up with a science amount, and converting that into usable science data.

The most relevant limitation that I can think of is that you must create your science subjects (the thing stored in the R&D center and used to track existing science reports) according to some pretty rigid standards. I have never found a way around (and I have spent a lot of time trying...) using ResearchAndDevelopment.GetExperimentSubject() to create usable science data. You have to give this function a celestial body, a science experiment defined in a sciencedefs.cfg file, an experimental situation and a biome (even if it's just an empty string).

You can still come up with lots of different methods for creating data within this limitation, Tarsier and CactEye both do so using their telescopes, and I've managed to fudge some of the variables to create asteroid science reports, but it does limit what you can create with it.

There's a lot of room to make interesting science experiments, but I'd need to know more about what you want to do to say anything else.

Link to comment
Share on other sites

In my failures mod I want to make inspecting a part an experiment (with a very small science return... If any), but I want to change the text, title and science value based on the state of the part.

If anything, at least to tap into the standard experiment GUI :P

Link to comment
Share on other sites

I think this is doable, though you have to use some slightly wonky formatting for your results.

The way to do this would be to create a science subject with a fixed celestial body and experimental subject and use the biome string to specify the part condition.


ScienceExperiment se = ResearchAndDevelopment.GetExperiment(id);
ScienceSubject su = ResearchAndDevelopment.GetExperimentSubject(se, ExperimentSituations.InSpaceHigh, FlightGlobals.Bodies[1], "Part Condition String" + "some kind of part ID number");

ScienceData data = new ScienceData(scienceAmount * su.dataScale, 1f, 0f, su.id, "Title bar string");

The science experiment id is what you have defined in the ScienceDefs.cfg file. Using a fixed experimental situation and celestial body takes those two elements out of consideration. You would presumably have a list of several possible part conditions, each with a short string associated with them. Appending a part ID number at the end would ensure that experiments would not be repeatable for the same part, but should be repeatable for other parts of the same type.

The first field in the science data constructor specifies the data amount (which divided by the data scale and multiplied by the SubjectValue and ScientificValue gives you the total science points), the next two values are for transmission and lab boost, which you probably don't care about. You can set your science value however you want, it doesn't necessarily have anything to do with the values set in the ScienceDefs.cfg file; you can change the science subject values too.

The su.id is the subject id; this thing: crewReport@KerbinInSpaceLowGrasslands. This must be valid, and must match the id generated in the step before. The formatting would be ridiculous in your case, since it has nothing to do with experimental situations and celestial bodies, but the biome string at the end is all that really matters. The title bar string can be whatever you want and is what shows up in the title of the experimental results page.

In your ScienceDefs.cfg file you would want to have science reports with the format KerbinInSpaceHighBroken/GoodCondition/NeedsRepair, etc... Having a part ID appended at the end won't matter for your science reports. You could also break things down further by generating science subjects and science reports based on part type (KerbinInSpaceHighEngineBroken), but all of that can be handled with your "biome" string at the end.

Link to comment
Share on other sites

I'm looking at Tarsier's source now. I pretty much get how the system works, however, I'd like it to be a little different.

Is it possible to have an experiment that is stored in the EVA kerbal? Basically, like sampling the ground.

I'd like the kerbal to fly to the part, inspect it, and receive a science report that HE stores, not the part.

Link to comment
Share on other sites

I'm looking at Tarsier's source now. I pretty much get how the system works, however, I'd like it to be a little different.

Is it possible to have an experiment that is stored in the EVA kerbal? Basically, like sampling the ground.

I'd like the kerbal to fly to the part, inspect it, and receive a science report that HE stores, not the part.

It should be, you would still need to attach the relevant module to the part, not the Kerbal (I have no idea how to do that anyway). So you would be using external event buttons ([KSPEvent(guiActiveUnfocused = true, externalToEVAOnly = true)]) and having the start experiment and transfer data methods all wrapped up in one button.

Another method might be to activate the experiment with the standard external button, then only transfer the data once you push the "keep data" button on the experimental results page. It wouldn't be difficult to add the code for that to the callback used by the results page.

Link to comment
Share on other sites

Well, the preliminary tests have been encouraging. There are some problems to iron out, but the main idea is working.

Of course, I realized when trying it out that in sandbox mode you cannot do any science, which means I would be locking out an important feature from the sandbox mode.

Looks like I have to actually go and write some GUI stuff. ._.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...