Jump to content

Adding Science and making it stick


Recommended Posts

Hi all,

I am trying to add Science outside of using experiments (both Career and Science Sandbox mode, KSP 1.0.4), and I found this:

ResearchAndDevelopment.Instance.AddScience(1.0f, TransactionReasons.Any);

If I then check to see if the science was added, I use this:

ResearchAndDevelopment.Instance.Science

I've verified that ResearchAndDevelopment.Instance.Science reflects the amount of science added using ResearchAndDevelopment.Instance.AddScience. The second I go back to the Space Center and look at the Science meter, it retains the value it had before entering Flight and altering the Science. As far as I can tell, the ResearchAndDevelopment scenario isn't saving the adjustment to Science when I switch the scene from Flight to Space Center. I'm also seeing that the Science readout in Flight doesn't reflect the change I did. Is there a way to tell the ResearchAndDevelopment scenario to save its new values? Is there another place to set Science other than in the ResearchAndDevelopment scenario?

Thanks for the help. :)

Edit: Nailed it! :) The problem is that I was adding science during the OnStart method. All I needed to do is wait a bit such as during OnUpdate or OnFixedUpdate.

Edited by Angel-125
Link to comment
Share on other sites

I'm more familiar with how R&D works outside of the Flight scene, and in that case, saving the game solved a similar issue for me.

GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);

However, I am not sure how forcing a save might affect reverting, etc. when in the Flight scene.

Link to comment
Share on other sites

You may need to fire the onScienceModified event, e.g.

GameEvents.onScienceModified.Fire(1.0, TransactionReasons.Any);

You may not need to do the other call in this case (the R&D center may have an event handler for that event). You'll either need to experiment or look for a mod that does something similar...

Link to comment
Share on other sites

As I recall that method takes TransactionReason as a parameter. Try different reasons. I've tried the "RnDs" value and everything was fine as long as I could see. If nothing helps, there's also the method CheatAddScience.

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