0

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?

Kietz
  • 1,186
  • 11
  • 19

1 Answers1

3

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.

R. Jason Sams
  • 1,469
  • 9
  • 10