question - How do I get the pxcor of the most right patch

60 views
Skip to first unread message

רם תמיר

unread,
Oct 2, 2022, 9:26:32 AM10/2/22
to netlogo-users
Hi
I have patches in different colors. I'm trying to get the pxcor of a green patch that is furthest to the right.  How can I do that? I'm adding an image for clarityCapture.PNG

Wannes...@hotmail.be

unread,
Oct 3, 2022, 10:12:53 AM10/3/22
to netlogo-users
Try the following, it should do the trick. You look at all green patches, take the one with the highest pxcor, and then return that pxcor

[pxcor] of max-one-of(patches with [color = green]) [pxcor] 



Op zondag 2 oktober 2022 om 15:26:32 UTC+2 schreef ra...@sng-edu.org:

Stephen Guerin

unread,
Oct 3, 2022, 12:38:26 PM10/3/22
to Wannes...@hotmail.be, netlogo-users
Small typo in the with clause that should be pcolor instead of color:

   [pxcor] of max-one-of patches with [pcolor = green] [pxcor]  

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/cafc16cf-766f-4ce4-aaca-4dc8c6809418n%40googlegroups.com.

Wannes...@hotmail.be

unread,
Oct 4, 2022, 5:25:05 AM10/4/22
to netlogo-users
Oh right. Somehow I keep making that same mistake, specifically for patches. Good thing Netlogo always points it out to me.

Op maandag 3 oktober 2022 om 18:38:26 UTC+2 schreef stephen.guerin:

רם תמיר

unread,
Oct 6, 2022, 1:10:21 PM10/6/22
to netlogo-users
Thank you both for the replies. I've tried your solution, but it gives me an error that I can't figure out. I'm trying to assign it to a variable like this:
actual-width  =  [pxcor] of max-one-of patches with [pcolor = green + 1] [pxcor] but it gives me an Expect command error. I've looked up the syntax and it looks fine, seems like all the brackets that should be there are there. What am I missing?

Wannes...@hotmail.be

unread,
Oct 6, 2022, 2:00:04 PM10/6/22
to netlogo-users
The syntax error is not in choosing the patch but rather in how you are assigning it to a variable. In Netlogo you assign a value to a variable by using: `set actual-width ... `
`=` is only used for logical expressions.


Op donderdag 6 oktober 2022 om 19:10:21 UTC+2 schreef ra...@sng-edu.org:

רם תמיר

unread,
Oct 7, 2022, 10:33:28 AM10/7/22
to netlogo-users
That's right and so obvious. Using = is so ingrained in me that I don't even see it and keep making that mistake. Thanks.
Reply all
Reply to author
Forward
0 new messages