Question

I tried to set a script global from within whatever.rs:

uint32_t a = 2;
void set_a_from_float(float x) {
    // more processing in real life
    a = (uint32_t) x;
}
ScriptC_whatever w = new ScriptC_whatever(mRS);
w.invoke_set_a_from_float(3.0f);
Log.d("ContrivedExample:", ""+w.get_a()); // logs 2

This is a silly example and I know I can just use the automatically generated getters/setters, but this error still seems counter-intuitive.

Why wouldn't this work?

Was it helpful?

Solution

The reflected .java file will cache the initial value set in the script. If the value is updated from a .set() the cached value will be updated. .get() returns the cached value.

For performance reason we do not update the cached value when written from the script. To send a value back to a .java file you can either read back from an rs_allocation or use rsSendToClient*() from the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top