Modify to fix context from patches to observer netlogo












0















What are the general rules to convert a code from patches to observer context?
For example, if I have a code like this, how should I modify it to convert the button from patches to observer context?
if numRed <= numYellow [set pcolor red]
if numYellow < numRed [set pcolor yellow]
if numGreen < numBlue [set pcolor green]










share|improve this question

























  • Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

    – JenB
    Nov 14 '18 at 10:17
















0















What are the general rules to convert a code from patches to observer context?
For example, if I have a code like this, how should I modify it to convert the button from patches to observer context?
if numRed <= numYellow [set pcolor red]
if numYellow < numRed [set pcolor yellow]
if numGreen < numBlue [set pcolor green]










share|improve this question

























  • Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

    – JenB
    Nov 14 '18 at 10:17














0












0








0








What are the general rules to convert a code from patches to observer context?
For example, if I have a code like this, how should I modify it to convert the button from patches to observer context?
if numRed <= numYellow [set pcolor red]
if numYellow < numRed [set pcolor yellow]
if numGreen < numBlue [set pcolor green]










share|improve this question
















What are the general rules to convert a code from patches to observer context?
For example, if I have a code like this, how should I modify it to convert the button from patches to observer context?
if numRed <= numYellow [set pcolor red]
if numYellow < numRed [set pcolor yellow]
if numGreen < numBlue [set pcolor green]







netlogo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:17









JenB

8,46911036




8,46911036










asked Nov 14 '18 at 0:15









Neena saskiaNeena saskia

32




32













  • Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

    – JenB
    Nov 14 '18 at 10:17



















  • Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

    – JenB
    Nov 14 '18 at 10:17

















Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

– JenB
Nov 14 '18 at 10:17





Please actually look at the tag description before adding a tag. Many words in programming are used for multiple different meanings, but a tag is only for one meaning.

– JenB
Nov 14 '18 at 10:17












1 Answer
1






active

oldest

votes


















2














There are no general rules as such. But the most common way to change contexts is with the primitive ask. Look at this code:



to testme
ask n-of 10 patches
[ set pcolor red
]
end


The procedure is in observer context. That is, it is written from the perspective of an outsider looking at the model. Then the ask randomly selects 10 patches. The code switches perspective (at the open square bracket) and sort of pretends it's the first of those randomly selected patches. That patch sets its color (pcolor) to red. Then the perspective switches to the second randomly selected patch. It also thinks to itself to change colour. While the code is running through those 10 patches, it is in patch context. The the close square bracket ends the code block, simultaneously ending the patch context and jumping back out to the observer context.



If your code is in patch context (or link context or turtle context), then you have to tell it which patches (or links or turtles) to be applying the code to. The default is all. Try this:




  • open a new NetLogo model

  • create a button: In the dialogue box for that button, use the dropdown box at the top to make it patches context. In the code box, type set pcolor red


Press the button and all patches will turn red.



I believe that a beginner in NetLogo should write every procedure from the observer context. This means that all the commands to patches and turtles are contained within clear ask <agentset> [ <do something > ] structures. It is easier for you to keep track of what you are doing and which model entities are doing it.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291356%2fmodify-to-fix-context-from-patches-to-observer-netlogo%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    There are no general rules as such. But the most common way to change contexts is with the primitive ask. Look at this code:



    to testme
    ask n-of 10 patches
    [ set pcolor red
    ]
    end


    The procedure is in observer context. That is, it is written from the perspective of an outsider looking at the model. Then the ask randomly selects 10 patches. The code switches perspective (at the open square bracket) and sort of pretends it's the first of those randomly selected patches. That patch sets its color (pcolor) to red. Then the perspective switches to the second randomly selected patch. It also thinks to itself to change colour. While the code is running through those 10 patches, it is in patch context. The the close square bracket ends the code block, simultaneously ending the patch context and jumping back out to the observer context.



    If your code is in patch context (or link context or turtle context), then you have to tell it which patches (or links or turtles) to be applying the code to. The default is all. Try this:




    • open a new NetLogo model

    • create a button: In the dialogue box for that button, use the dropdown box at the top to make it patches context. In the code box, type set pcolor red


    Press the button and all patches will turn red.



    I believe that a beginner in NetLogo should write every procedure from the observer context. This means that all the commands to patches and turtles are contained within clear ask <agentset> [ <do something > ] structures. It is easier for you to keep track of what you are doing and which model entities are doing it.






    share|improve this answer




























      2














      There are no general rules as such. But the most common way to change contexts is with the primitive ask. Look at this code:



      to testme
      ask n-of 10 patches
      [ set pcolor red
      ]
      end


      The procedure is in observer context. That is, it is written from the perspective of an outsider looking at the model. Then the ask randomly selects 10 patches. The code switches perspective (at the open square bracket) and sort of pretends it's the first of those randomly selected patches. That patch sets its color (pcolor) to red. Then the perspective switches to the second randomly selected patch. It also thinks to itself to change colour. While the code is running through those 10 patches, it is in patch context. The the close square bracket ends the code block, simultaneously ending the patch context and jumping back out to the observer context.



      If your code is in patch context (or link context or turtle context), then you have to tell it which patches (or links or turtles) to be applying the code to. The default is all. Try this:




      • open a new NetLogo model

      • create a button: In the dialogue box for that button, use the dropdown box at the top to make it patches context. In the code box, type set pcolor red


      Press the button and all patches will turn red.



      I believe that a beginner in NetLogo should write every procedure from the observer context. This means that all the commands to patches and turtles are contained within clear ask <agentset> [ <do something > ] structures. It is easier for you to keep track of what you are doing and which model entities are doing it.






      share|improve this answer


























        2












        2








        2







        There are no general rules as such. But the most common way to change contexts is with the primitive ask. Look at this code:



        to testme
        ask n-of 10 patches
        [ set pcolor red
        ]
        end


        The procedure is in observer context. That is, it is written from the perspective of an outsider looking at the model. Then the ask randomly selects 10 patches. The code switches perspective (at the open square bracket) and sort of pretends it's the first of those randomly selected patches. That patch sets its color (pcolor) to red. Then the perspective switches to the second randomly selected patch. It also thinks to itself to change colour. While the code is running through those 10 patches, it is in patch context. The the close square bracket ends the code block, simultaneously ending the patch context and jumping back out to the observer context.



        If your code is in patch context (or link context or turtle context), then you have to tell it which patches (or links or turtles) to be applying the code to. The default is all. Try this:




        • open a new NetLogo model

        • create a button: In the dialogue box for that button, use the dropdown box at the top to make it patches context. In the code box, type set pcolor red


        Press the button and all patches will turn red.



        I believe that a beginner in NetLogo should write every procedure from the observer context. This means that all the commands to patches and turtles are contained within clear ask <agentset> [ <do something > ] structures. It is easier for you to keep track of what you are doing and which model entities are doing it.






        share|improve this answer













        There are no general rules as such. But the most common way to change contexts is with the primitive ask. Look at this code:



        to testme
        ask n-of 10 patches
        [ set pcolor red
        ]
        end


        The procedure is in observer context. That is, it is written from the perspective of an outsider looking at the model. Then the ask randomly selects 10 patches. The code switches perspective (at the open square bracket) and sort of pretends it's the first of those randomly selected patches. That patch sets its color (pcolor) to red. Then the perspective switches to the second randomly selected patch. It also thinks to itself to change colour. While the code is running through those 10 patches, it is in patch context. The the close square bracket ends the code block, simultaneously ending the patch context and jumping back out to the observer context.



        If your code is in patch context (or link context or turtle context), then you have to tell it which patches (or links or turtles) to be applying the code to. The default is all. Try this:




        • open a new NetLogo model

        • create a button: In the dialogue box for that button, use the dropdown box at the top to make it patches context. In the code box, type set pcolor red


        Press the button and all patches will turn red.



        I believe that a beginner in NetLogo should write every procedure from the observer context. This means that all the commands to patches and turtles are contained within clear ask <agentset> [ <do something > ] structures. It is easier for you to keep track of what you are doing and which model entities are doing it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 10:29









        JenBJenB

        8,46911036




        8,46911036






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291356%2fmodify-to-fix-context-from-patches-to-observer-netlogo%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine