The following if statement gives a syntax error, what is wrong with it?
The clue does not lie in the code excerpt that you provided. What was the complete error message?
But whatever is wrong with the if statement's syntax, the code excerpt contains several other errors.
1. The variable name $ns doesn't follow hoc's rules for positional arguments. If the statement
$nc = new NetCon(ns, $o1)
doesn't generate an error message when the interpreter first parses it, it will definitely produce an error when connect_cell() is called.
2. The conditional test
if (runtime=400)
will execute the conditional code as soon as the interpreter encounters it (in this case setting nc.weight to 0) because
runtime=400
is an assignment statement, not a test of whether runtime equals 400.
3. If you fix problem 2 by changing the conditional test to
if (runtime==400)
you may find that the conditional code is never executed. Why? If the value of runtime is calculated by adding up numbers that have nonzero fractional parts (i.e. numbers that are not exact integers), roundoff error may cause failure of the "numerical identity test"
runtime==400
Why not just use NetCon to send an event with negative weight at time t == 400 to the NetStim that you want to silence? Example: suppose the NetStim you want to silence is called ns. Then
objref nil, ncstumm
ncstumm = new NetCon(nil, ns)
ncstumm.weight = -1
will create a NetCon that you can use to shut off ns. How do you get ncstumm to deliver an event to ns at t==400 ms, and make this happen every time you launch a new simulation? Use an FInitializeHandler.
objref fih
fih = new FInitializeHandler("ncstumm.event(400)")
There you go. Put those 5 statements into your program, after model setup is complete but before you call finitialize() or run(). No need to check the value of t (or "runtime") at every fadvance(), and no worry about roundoff error. Be sure to read the Programmer's Reference documentation of the NetCon class's event() method and the FInitializeHandler.