New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect event order - playerEnteredNewGalaxy after shipWillExitWitchspace #208
Comments
Behaviour confirmed and it is because of this in PlayerEntity -enterGalacticWitchspace:
The [self witchEnd] part ends up calling the PlayerEntity -leaveWitchspace method, which contains the call to shipWillExitWitchspace. The question is, is this a bug in the code or a bug in the documentation? |
I think it is logically correct behavior described in the wiki.
|
Current system don't set in playerEnteredNewGalaxy. It's correct?
|
No (dang it). Re-opening issue. We'll need to think a bit more about it. |
I was hoping that just executing the playerEnteredNewGalaxy handler before the witchEnd call would be all that is needed to have this fixed, but unfortunately it seems that the truth is quite different. The methods called by witchEnd actually set up plenty of system stuff necessary for concluding a jump. Because of this, I don't think it's possible to put the playerEnteredNewGalaxy handler anywhere early enough to ensure that it runs before shipWillExitWitchspace, without changing existing functionality at the same time. Unless I have done my searches wrongly, it looks like that particular playerEnterednewGalaxy wiki entry was inserted in 2009, which implies that the intention was to have the order of events as described. But it looks like we've been having the event handler switch going on since at least 2011, which is plenty of years ago. Not sure when or why it was changed, or even whether it was intended or not, but it seems that this has been the status quo for a long time. That's why I hinted earlier that maybe the wiki entry change could be a much less painful fix. I think that the changes we may have to apply just to get the switch working without affecting anything could be substantial. They may even introduce other unwanted side -effects. Therefore, the best way forward is in my opinion:
|
This patch can help? Not tested! diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m
index f16aba0..2d21620 100644
--- a/src/Core/Entities/PlayerEntity.m
+++ b/src/Core/Entities/PlayerEntity.m
@@ -7254,8 +7254,6 @@ - (void) enterGalacticWitchspace
[self setBounty:0 withReason:kOOLegalStatusReasonNewGalaxy]; // let's make a fresh start!
cursor_coordinates = PointFromString([[UNIVERSE systemManager] getProperty:@"coordinates" forSystem:system_id inGalaxy:galaxy_number]);
-
- [self doScriptEvent:OOJSID("playerEnteredNewGalaxy") withArgument:[NSNumber numberWithUnsignedInt:galaxy_number]];
[self witchEnd]; // sets coordinates, calls exiting witchspace JS events
}
@@ -7530,6 +7528,10 @@ - (void) leaveWitchspace
[self clearRoleFromPlayer:NO];
}
}
+ if (galactic_witchjump)
+ {
+ [self doScriptEvent:OOJSID("playerEnteredNewGalaxy") withArgument:[NSNumber numberWithUnsignedInt:galaxy_number]];
+ }
[self doScriptEvent:OOJSID("shipWillExitWitchspace")];
[UNIVERSE setUpBreakPattern:[self breakPatternPosition] orientation:orientation forDocking:NO];
} |
Oh dear, I had completely forgotten about the galactic_witchjump variable. I tested the patch and it looks like it works. So it looks like we went straight to the second bulletpoint of my earlier comment. OK, I'll commit this fix and keep the issue open for a while to give a chance for testing to happen. @AndSDev: Thanks for lookiing into it. |
If there are no objections, I would like to proceed with closing this issue some time tomorrow. |
Issue is considered fixed. Closing. |
According to the documentation:
But in log:
Tested on oolite-trunk-1.85.0.160812-dev.mac (Mac OS X).
The text was updated successfully, but these errors were encountered: