views:

53

answers:

2

Hi I am trying to code something in Netlogo..I am using an existing model Chemical Equilibrium and am trying to implement the following:

turtles-own [speed ]

ask turtles [

;; set velocity ( ambient-temperature = 30 )
;; fd velocity
if temp  > 40 [ "speed" increases of turtles  ]  
ifelse temperature < 30 [ speed of turtles decreases]

]

;; to temp

but it does not seem to work

(it temperature is more than 40 the speed of the turtles increases if the temperature is less than 30 the speed of the turtles decreases) temperature is a slider on the model

the same for pressure ask turtles [

;; if pressure > 50 then speed increases of turtles
;; if pressure < 50 then speed decreases of turtles

]

;; to pressure

thanks

A: 

Thats a really good question. I recently started using netlogo (experimenting mostly) and I would like to know how you can do something similar (increase the speed of a car for example using a slider but not the speed-meter on the top of the screen).

I think you have to define a global variable but I am not sure yet how it works.

If anyone has an idea it would be really appreciated.

A: 

I think what you are trying to do is something like this:

turtles-own [speed]


to setup
  ca
  create-turtles 50 [
    set speed 1
  ]
end

to go
  ask turtles [
    if (temperature  > 40) [ 
      set speed min (list (speed + 1) 100) ;cap the speed at 100 otherwise it will shoot to infinity
    ]
    if (temperature < 30) [
      set speed max (list (speed - 1) 0); min speed is 0
    ]
    ;move
    forward speed
  ]  
end

I had to add minimum and maximum speeds (0 and 100 respectively) otherwise the speed would quickly shoot to innfinity. Also, "temperature" is a slider in my model.

Jose M Vidal