Update: I came up with this, and it seems to work. Are there any potential issues that would arise from this? org.nlogo.nvm.Context nvmContext = ((org.nlogo.nvm.ExtensionContext) context).nvmContext(); nvmContext.finished = false; command.perform(new org.nlogo.nvm.ExtensionContext((Workspace) context.workspace(), nvmContext), new Object[0]);
On Wednesday, January 8, 2020 at 6:01:35 AM UTC-5, TechnoRazor wrote: > > Ah, that makes sense. I'm using my extension to bind anonymous commands to > key presses, using the "system-hook" library. The anonymous commands are > called from the key pressed event thread. I assume I should create a new > Context, but how would I do that? > > On Tuesday, January 7, 2020 at 11:27:54 PM UTC-5, Bryan Head wrote: >> >> So I think what’s happening here is that the Context the AnonymousCommand >> is created with is ending and thus getting marked finished. The finished >> marker is how Contexts know whether or not to keep executing code. You >> can see this here: >> https://github.com/NetLogo/NetLogo/blob/hexy/netlogo-core/src/main/nvm/Context.java#L128-L137. >> >> Because it’s a do... while rather than a while, it will only prematurely >> end if there’s more than one command (which it seems is what you’re >> seeing). Regardless of the reason, using a Context past the end of it’s >> lifetime is definitely asking for trouble. >> >> How to workaround this depends on the context. Can you give an example of >> the usage of your extension? Also, what thread is this event being >> triggered from? >> >> On Tue, Jan 7, 2020 at 4:23 PM TechnoRazor <therealte...@gmail.com> >> wrote: >> >>> My NetLogo extension has a command that binds an anonymous command to an >>> event. On the event, the command is called using: >>> command.perform(context, new Object[0]); >>> in which context is the context when the anonymous command was first >>> bound. This seemed to work fine until recently, when I noticed something >>> peculiar. The first time the event occurs after the command is bound, it >>> only runs the first command in the anonymous command. This poses a problem >>> for me, since, for example, if I bound the command "[-> if true [ print >>> true ]]" then it would never print "true" on the first call. I have no idea >>> why this is, does someone have an idea of why this happens and how to avoid >>> it? Thanks in advance. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "netlogo-devel" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to netlog...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/netlogo-devel/de8251bd-4a06-4a2f-a936-edc7c55993e6%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/netlogo-devel/de8251bd-4a06-4a2f-a936-edc7c55993e6%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> Bryan Head >> PhD Candidate, Computer Science >> Center for Connected Learning and Computer-Based Modeling >> Department of Electrical Engineering and Computer Science >> Northwestern University >> > -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/a7822a7b-b18c-4f62-af97-f9b2c0b4f0bd%40googlegroups.com.