Question about how to reset gravity

I have some problems. I want to try to change the gravity on the grid node, so I add the following code (red box). However, the program cannot be compiled. It seems that the self.set-gravity function cannot pass variables but only constants. What should I do in this situation? Thank you for helping me with this puzzle.
the following figure shows the code that Cannot be compiled (with variable)
The error report is as follows
Python returned the following error: <class ‘TypeError’>
write_float(): incompatible function arguments. The following argument types are supported:
1. (self: taichi_core.SNode, arg0: List[int], arg1: float) -> None

Invoked with: <taichi_core.SNode object at 0x0000021962922FB8>, (0, 0, 0, 0, 0, 0, 0, 0), <taichi.lang.expr.Expr object at 0x0000021CA486C518>

Call Stack information:
File “C:\Users\xinjian\Desktop\New folder\LABVIEW function\MPM\MPM3D\”, line 21, in Getdata
File “C:\Users\xinjian\Desktop\New folder\LABVIEW function\MPM\MPM3D\”, line 202, in step
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 386, in decorated
primal(*args, **kwargs)
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 341, in call
self.materialize(key=key, args=args, arg_features=self.mapper.extract(args))
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 247, in materialize
taichi_kernel = taichi_kernel.define(taichi_ast_generator)
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 244, in taichi_ast_generator
File “C:\Users\xinjian\Desktop\New folder\LABVIEW function\MPM\MPM3D\”, line 158, in grid_op
File “C:\Users\xinjian\Desktop\New folder\LABVIEW function\MPM\MPM3D\”, line 87, in set_gravity
self.gravity[None] = g
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 282, in setitem
self(i, j)[index] = item[i][j]
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 194, in setitem
self.setter(value, *key)
File “C:\Users\xinjian\AppData\Roaming\Python\Python36\site-packages\taichi\lang\”, line 171, in setter
snode.write_float(key, value)

TypeError: write_float(): incompatible fu

However, the following figure shows the code that can be compiled (but only constant)