Jump to content

Help! Update() doesen't work!


Recommended Posts

Can someone help? I'm having problems with my code. I'm trying to make a part module which would trigger some functions when part cant get any fuel. in my codepart its like

public void onUpdate () {

double anti = this.part.RequestResource ("Antimatter", 20);
double EM = this.part.RequestResource ("Electric Matter", 1);


if (anti <= 20 ^ EM >= 1) stabilizeField (antiFieldState);
else calculateExplosions (antiFieldState);


}

Link to comment
Share on other sites

Public void onUpdate() should be public void Update ()(if using monobehaviour callbacks) or public override void OnUpdate () if using ksp callbacks from PartModule?*

*questionmark because im a total noob at c#

Edited by landeTLS
Link to comment
Share on other sites

Ok I'll try. Hope it works :)

- - - Updated - - -

I dont think it works. My code:

public override void OnUpdate () {





double anti = this.part.RequestResource ("Antimatter", 20);
double EM = this.part.RequestResource ("Electric Matter", 1);


if (anti <= 20 ^ EM >= 1) stabilizeField (antiFieldState);
else calculateExplosions (antiFieldState);


}

It should work and I actually have a debug messaging after that but it shows nothing in the log. Stabilize field shows in the debug that it works and calculate explosions explodes the part.

Edited by JuhaJGamer
Adding stuff
Link to comment
Share on other sites

Remember that OnUpdate() only runs if the part is the part is active (staged). I suspect this may be your issue.

Update() always runs, though you make want to run some checks that the part is in flight (not in the editor) depending what you want to do.

Link to comment
Share on other sites

O i must have remembered wrong. I thought OnUpdate () ran regardless of staging but OnFixedUpdate () ran only after staging. Sorry for the confusion. Then as lo-fi said it is better to use Update () which runs regardless of staging since this is unitys own frame callback. That is unless you want to integrate some functionality with ksps staging timeline.

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