Xaranth Posted November 26, 2012 Share Posted November 26, 2012 I have a script. It is an effect script. It suffers from a race condition. I don't know how to fix it. :ermm: If it were an object script, I'd add a timer block in the gamemode, but I can't use GameMode blocktype in effect scripts, can I? scn DARC07scptTeleporterBuildEffect float fPlayerZ float fTeleZAng float fTeleXPos float fTeleYPos begin ScriptEffectStart Set fPlayerZ to player.getAngle Z Set fTeleXPos to (256 * (sin fPlayerZ)) Set fTeleYPos to (256 * (cos fPlayerZ)) Set fTeleZAng to (fPlayerZ - 90) DARC07refActiTeleporterDummyREF01.Disable DARC07refActiTeleporterDummyREF01.moveTo player fTeleXPos fTeleYPos 0 DARC07refActiTeleporterDummyREF01.setAngle Z fTeleZAng ; Set DARC07qstTeleporterControl.rActiveTeleporter to DARC07refActiTeleporterDummyREF01.PlaceAtMe DARC07actiTeleporter ; Set DARC07qstTeleporterControl.rActiveMarker to DARC07refActiTeleporterDummyREF01.PlaceAtMe XMarkerHeading ; DARC07refActiTeleporterDummyREF01.moveTo DARC07refTeleDummyRef ; DARC07refActiTeleporterDummyREF01.Enable end Commented lines bollix up because of race condition issues. The DummyREF hasn't finished moving, so they behave unpredictably. Can I fix this within the effect script, or do I need to break it up and do more building with an object script? -X, headed for bed. Link to comment Share on other sites More sharing options...
luthienanarion Posted November 26, 2012 Share Posted November 26, 2012 (edited) What do you mean when you say that it suffers from a race condition? You can use different blocks in an effect script, but code in the ScriptEffectStart block will not be interrupted by a GameMode or MenuMode block running. It's not something commonly done. Another option that might be simpler to implement would be for your effect to give the player a token with an object script that handled moving things around with timers and then deleting itself. Edited November 26, 2012 by luthienanarion Link to comment Share on other sites More sharing options...
Xaranth Posted November 26, 2012 Author Share Posted November 26, 2012 (edited) What do you mean when you say that it suffers from a race condition? You can use different blocks in an effect script, but code in the ScriptEffectStart block will not be interrupted by a GameMode or MenuMode block running. It's not something commonly done. Another option that might be simpler to implement would be for your effect to give the player a token with an object script that handled moving things around with timers and then deleting itself. By race condition I mean that sequential calls are being made before prior calls have evaluated completely. Which results in the teleporter being built in completely random places, usually the wrong cell. And glory, I forgot all about tokens, which just shows that I'd been beating my head against the wall far, far too long on that constructor. Actually, I woke up with it fairly clear in my brain that what I should do is do the moving of the dummy with the Effect Script and put the actually building bits in a GameMode script on my dummy. I'll try that and see what happens. If it doesn't play well, I'll go with tokens. Thank you. -X EDIT: To say which block I meant. Meh, not enough coffee. Edited November 26, 2012 by Xaranth Link to comment Share on other sites More sharing options...
Xaranth Posted November 26, 2012 Author Share Posted November 26, 2012 It (You can't hear it, but I'm laughing like Ghaleon right now. And not Eternal Blue Ghaleon. Silver Star Story Ghaleon.) Link to comment Share on other sites More sharing options...
rickerhk Posted November 26, 2012 Share Posted November 26, 2012 A lot of glitchy problems with scripting this game are caused by trying to do everything in one frame. A scripteffectStart block runs exactly once. PlaceAtMe takes time. Handing it off to a token allows at least a frame to pass while it is being added to the player. A scripteffectUpdate block would also work but then it might be more complicated depending on what applied the effect. Link to comment Share on other sites More sharing options...
Xaranth Posted November 27, 2012 Author Share Posted November 27, 2012 A lot of glitchy problems with scripting this game are caused by trying to do everything in one frame. A scripteffectStart block runs exactly once. PlaceAtMe takes time. Handing it off to a token allows at least a frame to pass while it is being added to the player. A scripteffectUpdate block would also work but then it might be more complicated depending on what applied the effect. Yeah! I no longer have to worry about spinning new threads off to handle some of my graphics processing, I can get Race conditions just by doing things the way I feel like it. Yeah, anyway. Given that the effect is instantaneous with zero duration... I didn't want to plumb the depths of blocktyping for it. I passed off a lot of the secondary processing to the dummy object itself, rather than trying to get my ingestible to do it, which worked well enough for me to do the Ghaleon Laugh. Now I just have to go through the tedious business of coding a bunch of nested message Forms. Whee. -X Link to comment Share on other sites More sharing options...
Recommended Posts