Hello,
Are you using the Rapid IoT Studio or the MCUXpresos IDE? I believe that you are using the studio with the information you provided, nonetheless, could you please help me confirm?
Also, I'm not sure I fully get what you are trying to do, but I believe that you might find helpful one of the following three examples that work with variables management. Could you please check those? I believe those can help you as a base.
Regards,
Estephania