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. Would it be correct to construct 
a new Context each time using "public Context(Context context, AgentSet 
agents)"?

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
>  
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FNetLogo%2FNetLogo%2Fblob%2Fhexy%2Fnetlogo-core%2Fsrc%2Fmain%2Fnvm%2FContext.java%23L128-L137&sa=D&sntz=1&usg=AFQjCNEUgl45mp80P6vkGMsfnWMO4u4JuA>.
>  
> 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 
> <javascript:>> 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 <javascript:>.
>> 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/52d8cf01-1662-4b30-bb53-16f3f717d00c%40googlegroups.com.

Reply via email to