Q.M
Q.M

Reputation: 41

Netlogo: Call commands from text files?

Is it possible to call commands from a text file? The goal I am trying to achieve is to have a text file with strings of commands ,the user can input this file in and the system will then call the commands. What I have so far is from studying the file input example is:

 to load-test
    let file user-file
    file-open file
    let lines []
    while [not file-at-end?]
    [
        let a-line file-read 
        set lines lput a-line lines
    ]
    file-close
    end

The list lines will contain all of the lines of the file, Then use a foreach on the list to select each element at a time to execute. I am aware of the primitive "read-from-string" but it only seems to work from values rather than commands. Is there any method of achieving this or something similar?

Upvotes: 2

Views: 57

Answers (1)

mattsap
mattsap

Reputation: 3806

If the command is a reporter, you can use runresult, otherwise, you could use run

See: https://ccl.northwestern.edu/netlogo/docs/dictionary.html#run

For example:

show runresult "3 + 2"

It's a little weird that you're storing commands in a text file, why not just use an nls file to store the extra commands?

Upvotes: 1

Related Questions