Jump to content

Get the science value of an experiment before it is run?


Recommended Posts

I'm trying to do a check for an experiment's science values before the experiment is run to stop worthless science popups in my addon.

I've tried using getsciencevalue and getnextsicencevalue, but I just get some error about object state.

Additionally, how does one intact with the experiment dialog? I'l like to be able to hide the results and/or condition execution based upon user input on the result page.

Link to comment
Share on other sites

ScienceAlert uses the following (experiment being a simple ResearchAndDevelopment.GetExperiment(expid)):

float CalculateNextReportValue(ScienceSubject subject, List<ScienceData> stored)
{
if (stored.Count == 0)
return ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject);

float experimentValue = ResearchAndDevelopment.GetNextScienceValue(experiment.baseValue * experiment.dataScale, subject);

if (stored.Count == 1)
return experimentValue;


// for two or more, we'll have to estimate. Presumably there's some
// kind of interpolation going on. I've found that just dividing the previous
// value by four is a good estimate.
return experimentValue / Mathf.Pow(4f, stored.Count - 1);
}

As to the second question, I think a couple of DMagic's experiments change the results dialog callbacks and do the dialog display on their own. That'd be a great place to start

Link to comment
Share on other sites

Hmm, I've tried that. At least, I think I'm doing the same thing. I get data values of 1.5 for crew reports on the launchpad even when they have always been run. It looks like it always return the science cap. datascale returns 1, when it should be 0 for the crew report.

var currentScienceSubject = ResearchAndDevelopment.GetExperimentSubject(currentExperiment.experiment, currentSituation, currentBody, currentBiome);
var currentScienceValue = ResearchAndDevelopment.GetScienceValue(currentExperiment.experiment.baseValue * currentExperiment.experiment.dataScale, currentScienceSubject);

currentExperiment is the current experiment module that I'm checking. I run through them each time the plugin in activated or there is change in situation.

edit: nm, its not working.

Edited by WaveFunctionP
Link to comment
Share on other sites

Its not returning the proper values. I'm getting the values that would be returned if the experiment had never been ran. I'm looking for the number that would show up on the results dialog.

edit: I'm an idiot as usual. was using getsciencevalue instead getnextsciencevalue.

doh!

Edited by WaveFunctionP
Link to comment
Share on other sites

getScienceValue always returns the full science value regardless of how many times you've recovered data from that particular experiment and situation. getNextScienceData returns how much science you will get the next time you use the experiment after recovering the current value. At least, that is what is happening to me. I don't really need the actual value to be honest, simply knowing if it has been run before is good enough.

If I can't check the current experiment's value, is there a way to check the r&D facility for previously run experiments at least?

Link to comment
Share on other sites

getScienceValue always returns the full science value regardless of how many times you've recovered data from that particular experiment and situation.

No, it returns the right value. There are a couple of less obvious things to watch out for.

First, are you getting the subject correctly? If you're using just ScienceUtil.GetExperimentBiome to get the biome, that won't work if the vessel is landed on a static object like the launchpad, sph, runway, or other non-biomes that still qualify as valid locations.

Second, when are you testing the value? I say this because I spent at least 10 minutes trying to figure out why the values printed in my Start (or Awake? I forget which now) method were wrong while on the launchpad when first writing ScienceAlert. If the vessel hasn't been placed to pad yet, you might get a bogus result.

Here is a snippet you can test. In a game without a crewReport recovered yet, launch a command pod. Check value while on launchpad

var vessel = FlightGlobals.ActiveVessel;
var situation = ScienceUtil.GetExperimentSituation(vessel);
var experiment = ResearchAndDevelopment.GetExperiment("crewReport");
string biome = string.Empty;

if (experiment.BiomeIsRelevantWhile(situation))
biome = vessel.landedAt != string.Empty ? vessel.landedAt : ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);

var subject = ResearchAndDevelopment.GetExperimentSubject(experiment, situation, vessel.mainBody, biome);
float scienceValue = ResearchAndDevelopment.GetScienceValue(experiment.baseValue * experiment.dataScale, subject);

Log.Write("Science Value of crewReport: {0}", scienceValue);

I get this:

[Log]: ScienceAlert, Science Value of crewReport: 1.5

Now recover the pod. Launch another pod check results again. I get this:

[Log]: ScienceAlert, Science Value of crewReport: 0

If you just want to see if the player has gathered any science for that experiment + situation + biome combination at all, it's just a simple subject.science > 0 check

Edited by xEvilReeperx
Improved snippet; now correctly handles biomeMask flag
Link to comment
Share on other sites

Looks like there is an issue with biomes. I do a running update on my vessel state, I save this state at certain points. It is how I detect transitions from one state to another. I've added some additional logging and I've notices utils was misreporting as you say. The good news is that your solution simplifies the search that I needed to do to find existing data on the vessel so that it is not rerun in a loop. I had been reconstructing the experiment masks by manually building a string for each possible situation mask. Now I can just do a contains check on the data and it appears to be working.

It is picking up an additional state on launch, where it thinks that the vessel is landed on shores. It still tries to return science values for invalid biomes.


[LOG 16:34:09.192] [For Science] Vessel in new experimental situation.
[LOG 16:34:09.192] [For Science] Checking experiment: crewReport@KerbinInSpaceHighGrasslands
[LOG 16:34:09.193] [For Science] data.subjectid: barometerScan@KerbinFlyingLow
[LOG 16:34:09.194] [For Science] data.subjectid: atmosphereAnalysis@KerbinFlyingLowShores
[LOG 16:34:09.194] [For Science] data.subjectid: crewReport@KerbinFlyingHigh
[LOG 16:34:09.195] [For Science] data.subjectid: barometerScan@KerbinFlyingHigh
[LOG 16:34:09.195] [For Science] data.subjectid: temperatureScan@KerbinFlyingHigh
[LOG 16:34:09.196] [For Science] data.subjectid: crewReport@KerbinInSpaceLow
[LOG 16:34:09.197] [For Science] data.subjectid: temperatureScan@KerbinInSpaceLow
[LOG 16:34:09.197] [For Science] ScienceValue availible: 5
[LOG 16:34:09.198] [For Science] Running experiment: mk1pod (Untitled Space Craft)
[LOG 16:34:09.198] [Experiments]: Setting FX Modules to 1...
[LOG 16:34:09.199] [Experiments]: FX Modules set: 1
[LOG 16:34:09.200] [For Science] Checking experiment: barometerScan@KerbinInSpaceHighGrasslands
[LOG 16:34:09.200] [For Science] Skipping: Experiment is not available.
[LOG 16:34:09.201] [For Science] Checking experiment: temperatureScan@KerbinInSpaceHighGrasslands
[LOG 16:34:09.201] [For Science] Skipping: Experiment is not available.
[LOG 16:34:09.202] [For Science] Checking experiment: gravityScan@KerbinInSpaceHighGrasslands
[LOG 16:34:09.203] [For Science] Skipping: No more science is available.
[LOG 16:34:09.203] [For Science] Checking experiment: atmosphereAnalysis@KerbinInSpaceHighGrasslands
[LOG 16:34:09.204] [For Science] Skipping: Experiment is not available.
[LOG 16:34:09.239] [For Science] Tranfering science to container.
[LOG 16:34:09.328] [For Science] Tranfering science to container.
[LOG 16:34:09.329] [Experiments]: Setting FX Modules to 0...
[LOG 16:34:09.329] [Experiments]: FX Modules set: 0
[LOG 16:34:09.484] [For Science] Tranfering science to container.
[LOG 16:34:09.628] [For Science] Vessel in new experimental situation.
[LOG 16:34:09.628] [For Science] Checking experiment: crewReport@KerbinInSpaceHighShores
[LOG 16:34:09.629] [For Science] data.subjectid: barometerScan@KerbinFlyingLow
[LOG 16:34:09.630] [For Science] data.subjectid: atmosphereAnalysis@KerbinFlyingLowShores
[LOG 16:34:09.630] [For Science] data.subjectid: crewReport@KerbinFlyingHigh
[LOG 16:34:09.631] [For Science] data.subjectid: barometerScan@KerbinFlyingHigh
[LOG 16:34:09.631] [For Science] data.subjectid: temperatureScan@KerbinFlyingHigh
[LOG 16:34:09.632] [For Science] data.subjectid: crewReport@KerbinInSpaceLow
[LOG 16:34:09.633] [For Science] data.subjectid: temperatureScan@KerbinInSpaceLow
[LOG 16:34:09.633] [For Science] Skipping: Found existing experiment data: crewReport@KerbinInSpaceHigh

The data.subjectid is me searching the science container for existing experiments. the experiment mask generated by sciencesubject.

var currentScienceSubject = ResearchAndDevelopment.GetExperimentSubject(currentExperiment.experiment, currentSituation, currentBody, currentBiome);
var currentScienceValue = ResearchAndDevelopment.GetScienceValue(currentExperiment.experiment.baseValue * currentExperiment.experiment.dataScale, currentScienceSubject);
Debug.Log("[For Science] Checking experiment: " + currentScienceSubject.id);

I've added a check for biomeisrelevant to string.empty the biome parameter for getexperimentsubject, which appears to resolve the issue of return invalid experiments. I'll need to test is more. I'm not sure if I'll need to do the same for situation.

Thanks again, evil. I've been banging my head on this too long. It's always something simple and thats the most frustrating part for me, because I know it. :P

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...