At the moment it's only possible to set the values for global variables via AMP.setState but not for variables declared inside amp-state.
Example:
AMP.setState(foo=123) -> is working
AMP.setState(myAmpState.foo=123)
where
<amp-state id="myAmpState">
<script type="application/json">
{
"foo": "234"
}
.....
is not working.
Current workaround is setting default variables.
@choumx @ericlindley-g